Valid JSON giving JSONDecodeError: Expecting , delimiter

后端 未结 2 1290
情深已故
情深已故 2020-12-04 18:16

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

Here is the snippet where it choking:

data = json.loads(\"\"\         


        
相关标签:
2条回答
  • 2020-12-04 18:33

    You need to add r before your json string.

    >>> st = r'{ "entry":{ "etag":"W/\"A0UGRK47eCp7I9B9WiRrYU0.\"" } }'
    >>> data = json.loads(st)
    >>>
    
    0 讨论(0)
  • 2020-12-04 18:35

    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.\"" } }""")

    see here for more information

    0 讨论(0)
提交回复
热议问题