Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
onenote响应字符串中的python文本解析_Python_Json_Parsing - Fatal编程技术网

onenote响应字符串中的python文本解析

onenote响应字符串中的python文本解析,python,json,parsing,Python,Json,Parsing,如何将这样的字符串解析为数据结构。我应该使用什么解析工具 u'{\r\n "@odata.context":"https://www.onenote.com/api/v1.0/$metadata#me/notes/notebooks(\'0-AB87696357344A7E%212879\')/sections(parentNotebook(id,name,self),parentSectionGroup(id,name,self))","value":[\r\n {\r\n

如何将这样的字符串解析为数据结构。我应该使用什么解析工具

u'{\r\n  "@odata.context":"https://www.onenote.com/api/v1.0/$metadata#me/notes/notebooks(\'0-AB87696357344A7E%212879\')/sections(parentNotebook(id,name,self),parentSectionGroup(id,name,self))","value":[\r\n    {\r\n      "id":"0-AB87696357344A7E!2881","self":"https://www.onenote.com/api/v1.0/me/notes/sections/0-AB87696357344A7E!2881","createdTime":"2017-05-18T01:14:32.977Z","name":"Untitled Section","createdBy":"Jason","createdByIdentity":{\r\n        "user":{\r\n          "id":"AB87696357344A7E","displayName":"Jason"\r\n        }\r\n      },"lastModifiedBy":"Jason","lastModifiedByIdentity":{\r\n        "user":{\r\n          "id":"AB87696357344A7E","displayName":"Jason"\r\n        }\r\n      },"lastModifiedTime":"2017-05-18T02:19:00.587Z","isDefault":false,"pagesUrl":"https://www.onenote.com/api/v1.0/me/notes/sections/0-AB87696357344A7E!2881/pages","parentNotebook@odata.context":"https://www.onenote.com/api/v1.0/$metadata#me/notes/notebooks(\'0-AB87696357344A7E%212879\')/sections(\'0-AB87696357344A7E%212881\')/parentNotebook(id,name,self)/$entity","parentNotebook":{\r\n        "id":"0-AB87696357344A7E!2879","name":"Companies and sectors","self":"https://www.onenote.com/api/v1.0/me/notes/notebooks/0-AB87696357344A7E!2879"\r\n      },"parentSectionGroup@odata.context":"https://www.onenote.com/api/v1.0/$metadata#me/notes/notebooks(\'0-AB87696357344A7E%212879\')/sections(\'0-AB87696357344A7E%212881\')/parentSectionGroup(id,name,self)/$entity","parentSectionGroup":null\r\n    }\r\n  ]\r\n}'

正如SuperSaiyan在评论中提到的,这是一个JSON字符串。因此,可以使用json库轻松解析:

import json
json_data = json.loads(
    u'{\r\n  "@odata.context":"https://www.onenote.com/api/v1.0/$metadata#me/notes/notebooks(\'0-AB87696357344A7E%212879\')/sections(parentNotebook(id,name,self),parentSectionGroup(id,name,self))","value":[\r\n    {\r\n      "id":"0-AB87696357344A7E!2881","self":"https://www.onenote.com/api/v1.0/me/notes/sections/0-AB87696357344A7E!2881","createdTime":"2017-05-18T01:14:32.977Z","name":"Untitled Section","createdBy":"Jason","createdByIdentity":{\r\n        "user":{\r\n          "id":"AB87696357344A7E","displayName":"Jason"\r\n        }\r\n      },"lastModifiedBy":"Jason","lastModifiedByIdentity":{\r\n        "user":{\r\n          "id":"AB87696357344A7E","displayName":"Jason"\r\n        }\r\n      },"lastModifiedTime":"2017-05-18T02:19:00.587Z","isDefault":false,"pagesUrl":"https://www.onenote.com/api/v1.0/me/notes/sections/0-AB87696357344A7E!2881/pages","parentNotebook@odata.context":"https://www.onenote.com/api/v1.0/$metadata#me/notes/notebooks(\'0-AB87696357344A7E%212879\')/sections(\'0-AB87696357344A7E%212881\')/parentNotebook(id,name,self)/$entity","parentNotebook":{\r\n        "id":"0-AB87696357344A7E!2879","name":"Companies and sectors","self":"https://www.onenote.com/api/v1.0/me/notes/notebooks/0-AB87696357344A7E!2879"\r\n      },"parentSectionGroup@odata.context":"https://www.onenote.com/api/v1.0/$metadata#me/notes/notebooks(\'0-AB87696357344A7E%212879\')/sections(\'0-AB87696357344A7E%212881\')/parentSectionGroup(id,name,self)/$entity","parentSectionGroup":null\r\n    }\r\n  ]\r\n}'
)
print(type(json_data))
print(json_data['value'][0]['createdBy'])
结果:

<type 'dict'>
Jason

杰森

<代码>你认为什么是可读的?导入<代码> JSON<代码>模块。然后使用:
obj=json.loads(您的字符串)
。然后你可以说:
print(obj[“@odata.context]”)
@Stephen Rauch。什么是可读的?如果你试图阅读它,你会如何解析它?谢谢。之后我把它放进了一个数据框
obj=json.load(r.text)df=pd.DataFrame(obj.get('value',[]))
。在
df中非常可读