python - 给出 json.decoder.JSONDecodeError 的有效 json: Expecting ',' delimiter
问题描述
我正在学习如何使用 python 处理 json,但它给了我一个错误。
这是我的代码
import json
people_string = """
{
"people": [
{
"name": "John Smith",
"phone": 666-625-7263,
"emails": ["john.smith@fakemail.com","johnsmith@workmail.com"],
"has_license": false
},
{
"name": "Jane Doe",
"phone": 666-625-7263,
"emails": null,
"has_license": true
}
]
}
"""
data = json.loads(people_string)
我收到以下错误:
Traceback (most recent call last):
File "c:/Users/Tanishq/Desktop/Tanishq-imp/python tutorials/json-35.py", line 20, in <module>
data = json.loads(people_string) #https://docs.python.org/3/library/json.html#encoders-and-decoders
File "C:\Users\Tanishq\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\Tanishq\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Tanishq\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 6 column 21 (char 71)
解决方案
您的错误在 json 文字字符串中,您phone
错误地定义了这对...
你应该做
....
"phone": "666-625-7263",
....
我的意思是,数字必须在“”之间,因为它是一个字符串,而不是一个数字(因为-符号)
推荐阅读
- javascript - TypeError: Date.prototype.Method 不是函数 - 方法突然不起作用
- python - 如何使用应用程序上下文来模拟烧瓶请求
- java - MongoDb 聚合,用于基于 ids 过滤列表并将此过滤列表映射到另一个字段
- php - 如何在 Woocommerce 我的帐户页面上打印登录的用户名?
- python - 无法运行 CX_Freeze 创建的 exe
- php - 从其他数组的多级数组中查找并获取数组键
- html - 为什么粘性侧边栏不浮动
- java - 如何获得实际平均值,而不是四舍五入?
- ruby-on-rails - PG::ConnectionBad - 无法连接到服务器:Mac OS X 上的连接被拒绝
- java - Java Cipher AES 不加密整个字符串