Why can't Python parse this JSON data?

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

I have this JSON in a file:

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


        
9条回答
  •  滥情空心
    2020-11-21 05:17

    Justin Peel's answer is really helpful, but if you are using Python 3 reading JSON should be done like this:

    with open('data.json', encoding='utf-8') as data_file:
        data = json.loads(data_file.read())
    

    Note: use json.loads instead of json.load. In Python 3, json.loads takes a string parameter. json.load takes a file-like object parameter. data_file.read() returns a string object.

    To be honest, I don't think it's a problem to load all json data into memory most cases.

提交回复
热议问题