马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
写了一个json数据,转换成python格式时报错了。import json
obj = """
{"name":"Wes",
"places_lived":["United States","Spain","Germany"],
"pet":"bull",
"siblings":[{"name":'Scott',"age":30,"pets":["Zeus","Zuko"]},
{"name":"Katie","age":38,"pets":["Sixes","Stache","Cisco"]}]
}
"""
result = json.loads(obj)
报错代码:Traceback (most recent call last):
File "11_22.py", line 10, in <module>
result = json.loads(obj)
File "C:\Users\asus\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\asus\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\asus\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 5 column 22 (char 105)
注意标点符号,json里面要求都是双引号"name":'Scott' import json
obj = """
{"name":"Wes",
"places_lived":["United States","Spain","Germany"],
"pet":"bull",
"siblings":[{"name":"Scott","age":30,"pets":["Zeus","Zuko"]},
{"name":"Katie","age":38,"pets":["Sixes","Stache","Cisco"]}]
}
"""
result = json.loads(obj)
print(result)
|