解析json并使用Curl获得多个值

时间:2019-01-28 06:35:15

标签: json curl

尝试解析从CURL返回的json以获取特定字段-

名称和描述。

这2个字段在JSON中将出现多次,并且所有值都应打印

 [
  {
    "Attributes": {
      "Process Type": [
        "Process"
      ],
      "Process Dev. Status": [
        "Business Owner Signoff"
      ],
      "Total No. T-code/Components": [
        "7"
      ],
      "02. L3 Business Process": [
        "Customer InStore Execution"
      ],
      "Process Status": [
        "Pre-Approved"
      ],
      "RelatedSapEntities": [
        "0"
      ],
      "03. QA Occurences": [
        "2"
      ],
      "No of Replaced Tests": [
        "1"
      ],
      "01. Value ": [
        "Customer InStore"
      ]
    },
    "Description": "Process Description:\n\nThis Process will login to the application and creates the new Task.After the Task has been created it will go to the Calendario page and verify the given details. Then navigate to the Oggi page opens the ToDo link and change the status of the Task.Then it navigates to the Calendrio page and verify the changed status.Finally Logout from the application.\n\n---------------------------------------------------------------\n\nLayout :\n\nCISCISE_AdvisorCreateTask\n\nRecorset:\n\nCISCISE_AdvisorCreateTask\n\n---------------------------------------------------------------\n\nSub Process/Child Process/Utility: \n\n1. UTL_SF_Login\n2. SF_Web_Advisor_CreateNewTask\n3. SF_Web_Advisor_CalendarioPage\n4. SF_Web_CreatedTask_OggiPage\n5. SF_Web_Task_InCorso_To_Completato\n6. SF_Web_Task_CompletatoTask_OggiPage\n7. UTL_SF_Logout",
    "Database": "Certify",
    "ID": 12519,
    "Name": "CISCISE_Advisor_CreateTask",
    "Path": " Test Automation\\Training\\POC\\SF Italy\\SFWeb\\CISCISE_Advisor_CreateTask",
    "Project": " Test Automation"
  },
  {
    "Attributes": {
      "Process Type": [
        "Process"
      ],
      "Process Dev. Status": [
        "Business Owner Signoff"
      ],
      "Total No. T-code/Components": [
        "7"
      ],
      "No of Replaced Tests": [
        "1"
      ],
      "02. L3 Business Process": [
        "Customer InStore Execution"
      ],
      "Process Status": [
        "Pre-Approved"
      ],
      "RelatedSapEntities": [
        "0"
      ],
      "03. QA Occurences": [
        "2"
      ],
      "01. Value Stream": [
        "Customer InStore"
      ]
    },
    "Description": "Process Description:\n\nThis Process creates a new Out of Office event.\nCalendario page is verified that whether the event created is populated in it. Calendar Details are verified.\nA new OOO event is created again for the same date and time and the error message obtained is validated.\n\n---------------------------------------------------------------\n\nLayout :\n\nCISCISE_SalesRep_OutOfOffice\n\nRecorset:\n\nCISCISE_SalesRep_OutOfOffice\n\n---------------------------------------------------------------\n\nSub Process/Child Process/Utility: \n\n1. UTL_SF_Login\n2. SF_Web_Create_OutOfOffice\n3. SF_Web_CreatedOutOfOffice_CalendrioPage\n4. SF_Web_Create_OutOfOffice\n5. SF_Web_OutOfOffice_Error\n6. UTL_SF_Logout",
    "Database": "Certify",
    "ID": 11610,
    "Name": "CISCISE_SalesRep_OutOfOffice",
    "Path": " Test Automation\\Training\\POC\\SF Italy\\SFWeb\\CISCISE_SalesRep_OutOfOffice",
    "Project": " Test Automation"
  }
]

如何循环到此代码中,我应该解析或字符串解析上面给出的代码吗?

请告诉我如何获取输出?

1 个答案:

答案 0 :(得分:0)

您可能想研究一下我最近开发的Unix工具-jtchttps://github.com/ldn-softdev/jtc

假设您的JSON位于file.json中:

bash $ jtc -w'<Name>l:' -w'<Description>l:' -l file.json
"Name": "CISCISE_Advisor_CreateTask"
"Description": "Process Description:\n\nThis Process will login to the application and creates the new Task.After the Task has been created it will go to the Calendario page and verify the given details. Then navigate to the Oggi page opens the ToDo link and change the status of the Task.Then it navigates to the Calendrio page and verify the changed status.Finally Logout from the application.\n\n---------------------------------------------------------------\n\nLayout :\n\nCISCISE_AdvisorCreateTask\n\nRecorset:\n\nCISCISE_AdvisorCreateTask\n\n---------------------------------------------------------------\n\nSub Process/Child Process/Utility: \n\n1. UTL_SF_Login\n2. SF_Web_Advisor_CreateNewTask\n3. SF_Web_Advisor_CalendarioPage\n4. SF_Web_CreatedTask_OggiPage\n5. SF_Web_Task_InCorso_To_Completato\n6. SF_Web_Task_CompletatoTask_OggiPage\n7. UTL_SF_Logout"
"Name": "CISCISE_SalesRep_OutOfOffice"
"Description": "Process Description:\n\nThis Process creates a new Out of Office event.\nCalendario page is verified that whether the event created is populated in it. Calendar Details are verified.\nA new OOO event is created again for the same date and time and the error message obtained is validated.\n\n---------------------------------------------------------------\n\nLayout :\n\nCISCISE_SalesRep_OutOfOffice\n\nRecorset:\n\nCISCISE_SalesRep_OutOfOffice\n\n---------------------------------------------------------------\n\nSub Process/Child Process/Utility: \n\n1. UTL_SF_Login\n2. SF_Web_Create_OutOfOffice\n3. SF_Web_CreatedOutOfOffice_CalendrioPage\n4. SF_Web_Create_OutOfOffice\n5. SF_Web_OutOfOffice_Error\n6. UTL_SF_Logout"
bash $