Why can't Python parse this JSON data?

后端 未结 9 2462
傲寒
傲寒 2020-11-21 05:06

I have this JSON in a file:

{
    \"maps\": [
        {
            \"id\": \"blabla\",
            \"iscategorical\         


        
9条回答
  •  独厮守ぢ
    2020-11-21 05:17

    As a python3 user,

    The difference between load and loads methods is important especially when you read json data from file.

    As stated in the docs:

    json.load:

    Deserialize fp (a .read()-supporting text file or binary file containing a JSON document) to a Python object using this conversion table.

    json.loads:

    json.loads: Deserialize s (a str, bytes or bytearray instance containing a JSON document) to a Python object using this conversion table.

    json.load method can directly read opened json document since it is able to read binary file.

    with open('./recipes.json') as data:
      all_recipes = json.load(data)
    

    As a result, your json data available as in a format specified according to this conversion table:

    https://docs.python.org/3.7/library/json.html#json-to-py-table

提交回复
热议问题