SMS*_*SMS 8 python json python-3.x
我正在运行以下代码-
import json
addrsfile =
open("C:\\Users\file.json",
"r")
addrJson = json.loads(addrsfile.read())
addrsfile.close()
if addrJson:
print("yes")
Run Code Online (Sandbox Code Playgroud)
但是给我以下错误-
import json
addrsfile =
open("C:\\Users\file.json",
"r")
addrJson = json.loads(addrsfile.read())
addrsfile.close()
if addrJson:
print("yes")
Run Code Online (Sandbox Code Playgroud)
有人帮我吗?
JSON文件就像-
{"name": "XYZ", "address": "54.7168,94.0215", "country_of_residence": "PQR", "countries": "LMN;PQRST", "date": "28-AUG-2008", "type": null}
{"name": "OLMS", "address": null, "country_of_residence": null, "countries": "Not identified;No", "date": "23-FEB-2017", "type": null}
Run Code Online (Sandbox Code Playgroud)
Han*_*nnu 13
您的json文件中有两条记录,并且json.loads()不能解码多个记录。您需要按记录进行记录。
请参阅Python json.loads显示ValueError:额外数据
或者,您需要重新格式化json以包含一个数组:
{
"foo" : [
{"name": "XYZ", "address": "54.7168,94.0215", "country_of_residence": "PQR", "countries": "LMN;PQRST", "date": "28-AUG-2008", "type": null},
{"name": "OLMS", "address": null, "country_of_residence": null, "countries": "Not identified;No", "date": "23-FEB-2017", "type": null}
]
}
Run Code Online (Sandbox Code Playgroud)
将再次被接受。但是不能有几个顶级对象。
| 归档时间: |
|
| 查看次数: |
39030 次 |
| 最近记录: |