Home > other >  Python met ISOdate while reading json file, complains, how to deal with to be able to read the data,
Python met ISOdate while reading json file, complains, how to deal with to be able to read the data,

Time:11-18

Json file content is as follows:
{
"Createtime" : ISODate (" the 2020-06-24 T06: and. 473 z "),
"Updatetime" : ISODate (" the 2020-07-09 T02:23:04. 553 z ")
}
{
"Createtime" : ISODate (" the 2020-06-24 T06: from. 86 z "),
"Updatetime" : ISODate (" the 2020-07-09 T02:35:42. 092 z ")
}
{
"Createtime" : ISODate (" the 2020-06-24 T07:00:33. 919 z "),
"Updatetime" : ISODate (" the 2020-08-14 T07:01:36. 704 z ")
}

Code:
With the open (" west. Json, "encoding=" utf-8 ") as f:
Json_file=json. The load (f, CLS=MyEncoder)
Print (json_file)

All bosses can help guide

CodePudding user response:

Behind the file content format not json createtime: must be within a double quotation marks

CodePudding user response:

Json file contains more than a json object, want to know how to deal with the

CodePudding user response:

Json data is data dictionary, data dictionary is a healthy corresponds to a value, called key/value pair, the healthy and the value of the data type can be different, but the healthy or value is only one type, your ISODate (" the 2020-06-24 T07:00:33. 919 z ") is clearly a string type, so have to use quotation marks that it is a string, because it has double quotes in your data, in order to avoid the interpreter identification errors, you can use single quotes, your json file can be changed to:
{
"Createtime" : 'ISODate (" the 2020-06-24 T06: and. 473 z ")',
"Updatetime" : 'ISODate (" the 2020-07-09 T02:23:04. 553 z ")'
}

CodePudding user response:

 {
"Createtime" : ISODate (" the 2020-06-24 T06: and. 473 z "),
"Updatetime" : ISODate (" the 2020-07-09 T02:23:04. 553 z ")
}
{
"Createtime" : ISODate (" the 2020-06-24 T06: from. 86 z "),
"Updatetime" : ISODate (" the 2020-07-09 T02:35:42. 092 z ")
}
{
"Createtime" : ISODate (" the 2020-06-24 T07:00:33. 919 z "),
"Updatetime" : ISODate (" the 2020-08-14 T07:01:36. 704 z ")
}


You the json data=json format string, illegal=do not conform to the json syntax
Specific have 3 point
1. The lack of the outermost layers of brackets []
2. The lack of a comma between each dict dictionary,
3. Inside each dict dictionary have extra ISODate - "need to string itself

To:

 

{
"Createtime" : "the 2020-06-24 T06: and. 473 z,"
"Updatetime" : "the 2020-07-09 T02:23:04. 553 z"
},
{
"Createtime" : "the 2020-06-24 T06: from. 86 z,"
"Updatetime" : "the 2020-07-09 T02:35:42. 092 z"
},
{
"Createtime" : "the 2020-06-24 T07:00:33. 919 z,"
"Updatetime" : "the 2020-08-14 T07:01:36. 704 z"
}
]

Is the (one) after the treatment way legal json string,
- "can be resolved properly

About JSON, can reference I (write) years ago tutorial:
JSON,