Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 Python 很陌生。我有一个这样的 JSON 响应:
{ "Code" : "Success", "LastUpdated" : "2012-10-19T08:52:10Z", }
我需要得到 的值Code,即Success。我怎样才能在 Python 中做到这一点?
Code
Success
json在文档中搜索。您将找到解释的 json 模块,并附有示例。
json
import json # ... you read here from the file data = '''{ "Code" : "Success", "LastUpdated" : "2012-10-19T08:52:10Z" }''' result = json.loads(data) print result['Code']
注意格式!!我在 之后删除了逗号"LastUpdated" : "2012-10-19T08:52:10Z",因为这不是有效的 json。
"LastUpdated" : "2012-10-19T08:52:10Z"