2017-08-09 8 views
0

ARC:アドバンストRESTクライアントから返されるjsonがPythonのRequestsモジュールによって返されるものと異なるのはなぜですか?

https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo?hl=en-US

私は.jsonファイルに返されたJSONを保存し、使用してパンダのデータフレームにそれを変換:

temp_json = pd.read_json('TempJson.json', orient='columns') 

をこれは素晴らしい作品。 しかし、私は具体的には、Pythonの2.7.13に要求モジュールを使用:

myResponse = requests.post(url, json= payload, headers = headers) 
jData = json.loads(myResponse.content) 

1)JSON構造はtemp_jsonよりもはるかに異なっており、2)それは完全に私のコードを難破船。どんな考え? temp_jsonから

スニペット:PythonのJSONから

{ 
    "expand": "schema,names", 
    "startAt": 0, 
"maxResults": 250, 
    "total": 3, 
    "issues": [ 
{ 
    "expand": "operations,editmeta,changelog,transitions,renderedFields", 
    "id": "1954523", 
    "key": "SPGC-14075", 
    "fields": {"summary": "QA: Build concentration support into CDC automation", 
    "issuetype": { 
     "self": "https://itec-jira.fmr.com/rest/api/2/issuetype/20", 
     "id": "20", 
     "description": "Default sub-task", 
     "iconUrl": "https://itec- 
jira.fmr.com/images/icons/issuetypes/subtask_alternate.png", 
     "name": "Sub task", 
     "subtask": true 

サンプル:

{ 
    "issues": [ 
{ 
    "key": "SPGC-25646", 
    "fields": { 
    "status": { 
     "statusCategory": { 
     "name": "To Do", 
     "self": "https://itec-jira.fmr.com/rest/api/2/statuscategory/2", 
     "id": 2, 
     "key": "new", 
     "colorName": "blue-gray" 
     },..... 
+1

2つの異なるjsonを表示してください。 – fazega

+0

スニペットを投稿しました。 – jenkelblankel

+0

@jenkelblankel:あなたのスニペットには違いはありません。辞書は非常によく等しいかもしれませんが、ちょうど異なる順序でリストされたキーを持っています。 – jwodder

答えて

0

json.loadsコンテンツはスクランブルの順序であろうようにハッシュされるPythonの辞書を作成します。 json.loadsが要求と一時ファイルの両方について同じdictを返すことを確認してください。それらが異なる場合、データは異なる。きれいなプリントライブラリを使用して、深くネストされたJSONをデバッグするのに役立てることができます。