我从zoho创作者api获得以下回复:
'var zohoview6 = {"Name_Registration":[ {"Approved":"Yes","Extension":1197,"ID_Number":"","Email":"xxx@yy.com","name_first ":"Test","Updated":false,"ID":"1257609000000083070","Authorised":true,"NameID":68 }]};'
然后我使用str.replace删除' var zohoview6 ='
但是,当我使用json.loads(str)加载生成的str时,我收到以下错误
ValueError: Extra data: line 1 column 192 - line 1 column 193 (char 191 - 192)
这是我得到很好的格式化的回报:
var zohoview6 =
{
"Name_Registration":[
{
"Approved":"Yes",
"Extension":1197,
"ID_Number":"",
"Email":"xxx@yy.com",
"name_first":"Test",
"Updated":false,
"ID":"1257609000000083070",
"Authorised":true,
"NameID":68
}]
};
我做错了什么?
答案 0 :(得分:1)
您还需要删除字符串末尾的额外;
,例如str.rstrip()
:
>>> import json
>>>
>>> s = 'var zohoview6 = {"Name_Registration":[ {"Approved":"Yes","Extension":1197,"ID_Number":"","Email":"xxx@yy.com","name_first ":"Test","Updated":false,"ID":"1257609000000083070","Authorised":true,"NameID":68 }]};'
>>> data = s.replace("var zohoview6 = ", "").rstrip(";")
>>> json.loads(data)
{u'Name_Registration': [{u'Updated': False, u'Extension': 1197, u'ID_Number': u'', u'Email': u'xxx@yy.com', u'Authorised': True, u'name_first ': u'Test', u'ID': u'1257609000000083070', u'NameID': 68, u'Approved': u'Yes'}]}