为什么Advanced REST Client返回的json与Python中的Requests模块返回的json不同?

时间:2017-08-09 18:54:58

标签: python json python-2.7

ARC:

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

我将返回的json保存在.json文件中,并使用以下命令将其转换为pandas数据框:

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

这很有效。 但后来我在Python 2.7.13中使用了requests模块,特别是:

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

1)json结构与temp_json有很大不同,2)它完全破坏了我的代码。知道为什么吗?

来自temp_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

来自python json的示例:

{
  "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 个答案:

答案 0 :(得分:0)

json.loads将创建一个python dict,它被散列,因此内容将以乱序排列。检查json.loads是否为请求和tempfile返回相同的dict。如果它们不同则数据不同。您可以使用漂亮的打印库来帮助您调试深层嵌套的json。