1.拿到手的是这样的一个log文件xxx.log:
orderPlan_test
b'{"eventType":"INSERT","schemaName":"qixiao_test","rowAfter":{"update_time":1575291953000,"order_plan_id":63000036509,"create_time":1575291953000,"click_through_json":"{\\"landingPage\\":\\"http://www.baidu.com\\",\\"landingPageFlag\\":0,\\"appName\\":\\"tgnr120205\\",\\"account\\":\\"tgnr120205\\"}"},"tableName":"qx_order_plan_click_through","timestamp":1575291953000}'
creative_test
b'{"rowBefore":{"update_time":1575291971000,"create_time":1575291971000,"submit_time":1575291971000,"name":"\xe6\x88\x91\xe7\x9a\x84\xe5\x88\x9b\xe6\x84\x8f20191202210554","prod_status":0,"landing_page":"http://www.baidu.com","id":64000017479,"prod_fail_type":0,"landing_page_flag":0,"material_json":"{\\"name\\":\\"\xe6\x88\x91\xe7\x9a\x84\xe5\x88\x9b\xe6\x84\x8f20191202210554\\",\\"url\\":1585,\\"title\\":\\"\xe5\xb9\xbf\xe5\x91\x8a\xe6\x96\x87\xe6\xa1\x88123\\",\\"previewData\\":{\\"buttonTitle\\":\\"\xe4\xba\x86\xe8\xa7\xa3\xe8\xaf\xa6\xe6\x83\x85\\"},\\"events\\":{\\"impressionUrl\\":null,\\"clickUrl\\":null},\\"feedId\\":\\"1569467048\\",\\"clickThrough\\":{\\"landingPage\\":\\"http://www.baidu.com\\",\\"landingPageFlag\\":0,\\"appName\\":\\"tgnr120205\\",\\"account\\":\\"tgnr120205\\"}}","status":1},"eventType":"UPDATE","schemaName":"qixiao_test","rowAfter":{"update_time":1575291971000,"create_time":1575291971000,"submit_time":1575291971000,"name":"\xe6\x88\x91\xe7\x9a\x84\xe5\x88\x9b\xe6\x84\x8f20191202210554","prod_status":1,"landing_page":"http://www.baidu.com","id":64000017479,"prod_fail_type":0,"landing_page_flag":0,"material_json":"{\\"name\\":\\"\xe6\x88\x91\xe7\x9a\x84\xe5\x88\x9b\xe6\x84\x8f20191202210554\\",\\"url\\":1585,\\"title\\":\\"\xe5\xb9\xbf\xe5\x91\x8a\xe6\x96\x87\xe6\xa1\x88123\\",\\"previewData\\":{\\"buttonTitle\\":\\"\xe4\xba\x86\xe8\xa7\xa3\xe8\xaf\xa6\xe6\x83\x85\\"},\\"events\\":{\\"impressionUrl\\":null,\\"clickUrl\\":null},\\"feedId\\":\\"1569467048\\",\\"clickThrough\\":{\\"landingPage\\":\\"http://www.baidu.com\\",\\"landingPageFlag\\":0,\\"appName\\":\\"tgnr120205\\",\\"account\\":\\"tgnr120205\\"}}","status":1},"tableName":"qx_creative_staging","timestamp":1575291971000}'
orderPlan_test
b'{"eventType":"INSERT","schemaName":"qixiao_test","rowAfter":{"update_time":1575291953000,"order_plan_id":63000036509,"create_time":1575291953000,"target_json":"[{\\"id\\":32,\\"type\\":1,\\"isAnti\\":false},{\\"id\\":33,\\"type\\":1,\\"isAnti\\":false},{\\"id\\":1,\\"type\\":210,\\"isAnti\\":false},{\\"id\\":3,\\"type\\":210,\\"isAnti\\":false},{\\"id\\":4,\\"type\\":210,\\"isAnti\\":false},{\\"id\\":2,\\"type\\":210,\\"isAnti\\":false}]"},"tableName":"qx_order_plan_target","timestamp":1575291953000}'
………………
2.明显可见每隔一行是个json格式,我现在希望将这个解析成dic。如果手动赋值,显然是可行的。
3.但是若果我用with open(filename,'r') 打开binlog文件,每一行结果是str格式,无法decode。请问该如何解决?
4.如果用with open(filename,'r+b')打开还是不行
5.1L回答的方法的问题是rowBefore,rowAfter里的中文编码,以及这两个key里嵌套的json格式不对