如何解析带双引号的json数据:
json.loads('
{
"time":"1410661614",
"text":"This is great",
"from":
{
"username":"mrb",
"id":"5071",
"full_name":"Free "Mrb"" #here is the problem
},
"id":"8090107"
}
')
python 返回:
ValueError: Expecting ',' delimiter: line 1 column 107 (char 106)
最佳答案
您可以通过转义双引号 (\"
) 轻松解决此问题
import json
json.loads("""
{
"time":"1410661614",
"text":"This is great",
"from":
{
"username":"mrb",
"id":"5071",
"full_name":"Free \\"Mrb\\""
},
"id":"8090107"
}
""")
正如评论中所说,最好修复 json 生成器以正确转义双引号,否则将很难解析和纠正 json 文件。
关于python 解析带双引号的json数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25931016/