簡體   English   中英

在Java中,如何從子數組中的值提取json數組的子集?

[英]How to extract a subset of json array from value in sub array, in java?

以下是我的json:

{
    "id": null,
    "extId": "720916740",
    "legacyId": null,
    "customerId": null,
    "accountId": null,
    "clientId": null,
    "publisherId": null,
    "name": "AllColumns1_1482141239819",
    "status": "ACTIVE",
    "operationStatus": null,
    "startDate": "20180101",
    "endDate": null,
    "channel": "SEARCH",
    "lastSyncDate": null,
    "linkStatus": "NOT_LINKED"
  },
  {
    "id": null,
    "extId": "720916743",
    "legacyId": null,
    "customerId": null,
    "accountId": null,
    "clientId": null,
    "publisherId": null,
    "name": "AllColumns2_1482141239819",
    "status": "ACTIVE",
    "operationStatus": null,
    "startDate": "20180101",
    "endDate": null,
    "channel": "SEARCH",
    "lastSyncDate": null,
    "linkStatus": "NOT_LINKED"
  },
  {
    "id": null,
    "extId": "720933833",
    "legacyId": null,
    "customerId": null,
    "accountId": null,
    "clientId": null,
    "publisherId": null,
    "name": "2TestCamp2_1482149078243",
    "status": "ACTIVE",
    "operationStatus": null,
    "startDate": "20180101",
    "endDate": null,
    "channel": "SEARCH",
    "lastSyncDate": null,
    "linkStatus": "NOT_LINKED"
  }

從上面的json,我想獲取名稱為“ 2TestCamp2_1482149078243”的id和extid。 我如何在JAVA中獲得它?

通常,首先要從json數組中找到該子數組,其值為“ 2TestCamp2_1482149078243”; 然后從該子數組獲取鍵id和ext id的值。

謝謝。 如果有人在這方面幫助我,那將很好。 我是java和json的新手。

String validate_name="2TestCamp2_1482149078243";

JSONObject object = new JSONObject(YOUR-JSON-Object);
JSONArray getArray = object.getJSONArray("Result");

for(JSONObject value:getArray)  //For Each loop to iterate the Objects from JSONArray
{
    if(value.getString("name").equals(validate_name))
    {
        value.getString("id");
        value.getString("extId");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM