-1

我对 Python 很陌生。我有一个这样的 JSON 响应:

{
  "Code" : "Success",
  "LastUpdated" : "2012-10-19T08:52:10Z",
}

我需要得到 的值Code,即Success。我怎样才能在 Python 中做到这一点?

4

2 回答 2

4

json文档中搜索。您将找到解释的 json 模块,并附有示例。

于 2012-10-19T09:09:53.747 回答
3
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。

于 2012-10-19T09:12:35.797 回答