我有下面的日志文件格式如下。我需要使用python将日志文件转换为json文件。怎么能做成呢?在
[2015-07-13 00:03:05,976] hostname 1499918592344 UZA:Anonymous:Anonymous96B50456767E74F51FD6AD2730C24133 http-nio-8080-exec-61 INFO Got successful response for the url GET http:/hostname/uza/accounts/123456789?loginTime=2017-07-13T00:03:04EDT
Response: {"accountBalance":{"pointsBalance":95053,"pointsName":"dd"},"accountStatus":{"accessType":"STANDARD","statusCode":"ACTIVE","statusMessage":"Unknown"},"userInformation":{"additionalInfo":{"memberID":"dd","updatedMemberID":"dd","memberLevel":"0"},"address":{"line1":"10249 dd","city":"dd Park","stateCode":"vv","postalCode":"777","countryCode":"rr"},"emailAddresses":[{"email":"dd@YAHOO.COM","type":"OTHER"}],"firstName":"gg","lastName":"gg","middleName":"C","phoneNumbers":[{"number":"5555","type":"OTHER"}],"title":"Mr"},"pricingTier":"ggg"} (HttpClientUtil)
导入pythons json library:
以字符串形式读入文件,并获取“Response:”子字符串之后的所有内容:
^{pr2}$从
response_string
获取python对象:如果需要,请在对该对象执行所需操作后将其写入文件:
使用
re.search()
和json
模块的解决方案:
^{pr2}$output.json
内容:相关问题 更多 >
编程相关推荐