2

我需要开发一个 python (v2.7) wsgi 应用程序来接收和解析从另一个网站发布的 json 对象中的数据。

示例 JSON 对象的格式如下。

{
  "BuildId":"4c53575f-36f48a7f1f37",
  "EventId":1,
  "EventName":"Archiving Complete",
  "EventDescription":"Fired each time the build products finish unzipping on an archive server after a successful build.",
  "ConfigurationId":2021,

  [
     {
        "archive_server":"CA",
        "ftp":"ftp://ABC.com/2011_V2/ccoderre_build_dev_build/2011.4.103.002",
        "dfs":"\\\\ABD.com\\ccoderre_build_dev_build\\2011.4.103.002"
     }
  ],
  "Changelists":
  [
     {
        "author":"mike",
        "description":"integrating from mainline\n",
        "number":1233242,
        "status":"OK",
        "submit_time":"\/Date(1305844615000)\/"
     }
  ],
  "InheritedChangelists":[],
  "CustomEventInfo":
  [
     {
        "Key":"ArchiveServer",
        "Value":"buildfsct"
     },
     {
        "Key":"HasSymbols",
        "Value":0
     }
  ]
}

如何使用 wsgi 获取(读取)“BuildId”、“ConfigurationId”、“ftp”等?谁能帮我?提前致谢!

4

1 回答 1

11

使用stdlibjson解析数据,结果是一个python字典:

def application(environ, start_response):
    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0

    request_body = environ['wsgi.input'].read(request_body_size)
    data = json.loads(request_body)
    build_id = data['BuildId']
    # etc.
于 2013-02-05T20:41:40.123 回答