2016-06-28 58 views
0

我想使用python解析POST HTTP響應。使用Python解析POST HTTP響應

我的回答是這樣的:

{ 
    "Result": 0, 
    "ResponseStatus": { 
    "ErrorCode": null, 
    "Message": null, 
    "StackTrace": null, 
    "Errors": null 
    }, 
    "SessionId": "68ebcd6f-0aef-420d-a12b-c953f8df8ed1", 
    "ResponseHeader": { 
    "Succeeded": true, 
    "Errors": [] 
    } 
} 

我想解析 - 「會話ID」 到第二個HTTP請求。 我該如何實現它?謝謝 !

+0

使用JSON模塊。 – syntonym

+2

請添加您使用的代碼來檢索該代碼,以便我們根據此代碼提供幫助。謝謝! –

回答

2
import json 
response = '{"Result": 0, "ResponseStatus": { "ErrorCode": null,"Message": null, "StackTrace": null, "Errors": null },"SessionId": "68ebcd6f-0aef-420d-a12b-c953f8df8ed1", "ResponseHeader": { "Succeeded": true, "Errors": [] } }' 
json_response = json.loads(response) 
print json_response['SessionId'] 

我猜你正在使用的urllib,我建議使用requests

+0

謝謝!我是Python新手。我會很感激,如果你會幫我寫第二個請求是基於第一個請求的SessionId的2個http請求 – abovebeyond15