json加载问题

时间:2018-03-11 16:38:12

标签: python json python-3.x

假设我有一个以下文件:

{"id":"3234", "brand": "xyz", "binary":"fdsjl2j3jrl90i0ife"}
{"id":"4332", "brand": "abc", "binary":"hshgfdgfdsl90i0fsf"}
{"id":"2542", "brand": "wtr", "binary":"gfdgf22332l90i0ife"}
{"id":"9922", "brand": "kjl", "binary":"fdsjl23gssdsfwe223"}

当我运行以下功能时:

import json

filename = 'udata'
filename2 = 'odata'

#initialize list
records = []

#add records from the file to the list
with open(filename) as f:
    for line in f:
        print(json.loads(line))

记录使用单引号返回数据('')而非""

{'id': '2542', 'brand': 'wtr', 'binary': 'gfdgf22332l90i0ife'}
{'id': '3234', 'brand': 'xyz', 'binary': 'fdsjl2j3jrl90i0ife'}
{'id': '4332', 'brand': 'abc', 'binary': 'hshgfdgfdsl90i0fsf'}
{'id': '9922', 'brand': 'kjl', 'binary': 'fdsjl23gssdsfwe223'}

通缉输出:

{"id":"3234", "brand": "xyz", "binary":"fdsjl2j3jrl90i0ife"}
{"id":"4332", "brand": "abc", "binary":"hshgfdgfdsl90i0fsf"}
{"id":"2542", "brand": "wtr", "binary":"gfdgf22332l90i0ife"}
{"id":"9922", "brand": "kjl", "binary":"fdsjl23gssdsfwe223"}

1 个答案:

答案 0 :(得分:0)

这真的不是问题。他们的意思完全相同。