提供JSONDecodeError的有效JSON:Expecting,分隔符 [英] Valid JSON giving JSONDecodeError: Expecting , delimiter

查看:2524
本文介绍了提供JSONDecodeError的有效JSON:Expecting,分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从youtube api解析json响应数据,但是我一直收到错误消息.

I'm trying to parse a json response data from youtube api but i keep getting an error.

这是令人窒息的片段:

data = json.loads("""{ "entry":{ "etag":"W/\"A0UGRK47eCp7I9B9WiRrYU0.\"" } }""")

..并且发生这种情况:

..and this happens:

JSONDecodeError: Expecting , delimiter: line 1 column 23 (char 23)

我已经确认它是有效的json,并且无法控制其格式,因此如何克服此错误?

I've confirmed that it's valid json and I have no control over the formatting of it so how can I get past this error?

推荐答案

在"之前需要r,或者将所有\替换为\\.从其他位置读取json,但从字符串本身读取内容.

You'll need a r before """, or replace all \ with \\. This is not something you should care about when read the json from somewhere else, but something in the string itself.

data = json.loads(r"""{ "entry":{ "etag":"W/\"A0UGRK47eCp7I9B9WiRrYU0.\"" } }""")

有关详情,请参见此处

这篇关于提供JSONDecodeError的有效JSON:Expecting,分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆