How to extract multiple JSON Objects from a JSON Array | Selenium Forum
M
Posted on 24/08/2016
Can some help me to extract multiple JSON Objects from a JSON Array.
The below is the JSON Array

{
"totalEntries" : 6,
"perPage" : 10,
"currentPage" : 0,
"entries" : [{
"subscriptionId" : 95110777,
"subscriptionRefId" : 94877825,
"product" : "Cisco ASA5506",
"sku" : "A-WX-AU-IM",
"quantity" : "5",
"quantityMeasure": "User",
"startDate" : "05/13/2013 11:50:07 PM",
"endDate" : "05/13/2016 11:50:07 PM",
"entitlementTag" : "CSR_1KV_AX_50M",
"entitlementName": "CSR_1KV_AX_50M"
}, {
"subscriptionId" : 11209384,
"subscriptionRefId" : null,
"product" : "Active User Spark Meet(with Meeting Center 1000)",
"sku" : "A-WX-AU-IM",
"quantity" : "50",
"quantityMeasure": "GB",
"startDate" : "05/13/2013 11:50:07 PM",
"endDate" : "05/13/2016 11:50:07 PM",
"entitlementTag" : null,
"entitlementName": null
}, {
"subscriptionId" : 11209384,
"subscriptionRefId" : null,
"product" : "Spark Active User (with WebEx)",
"sku" : "A-WX-AU-IM-RMSTG",
"quantity" : "5",
"quantityMeasure": null,
"startDate" : "05/13/2013 11:50:07 PM",
"endDate" : "05/13/2016 11:50:07 PM",
"entitlementTag" : null,
"entitlementName": null
}, {
"subscriptionId" : 11209384,
"subscriptionRefId" : null,
"product" : "Standalone Spark Message and Active Webex Messenger",
"sku" : "A-WX-AUIM-INC",
"quantity" : "50",
"quantityMeasure": "GB",
"startDate" : "05/13/2013 11:50:07 PM",
"endDate" : "05/13/2016 11:50:07 PM",
"entitlementTag" : null,
"entitlementName": null
}, {
"subscriptionId" : 11209384,
"subscriptionRefId" : null,
"product" : "Included Storage",
"sku" : "A-WX-STORAGE-ADD",
"quantity" : "50",
"quantityMeasure": "GB",
"startDate" : "05/13/2013 11:50:07 PM",
"endDate" : "05/13/2016 11:50:07 PM",
"entitlementTag" : null,
"entitlementName": null
}, {
"subscriptionId" : 95110836,
"subscriptionRefId" : 95110333,
"product" : "Cisco ASA5506 Fire Power",
"sku" : "A-WX-STORAGE-TAMC-PR",
"quantity" : "50",
"startDate" : "05/13/2013 11:50:07 PM",
"endDate" : "05/13/2016 11:50:07 PM",
"entitlementTag" : "CSR_1KV_AX_30M",
"entitlementName": null
} ]
}


I have written my logic as below

JSONArray dataArray=(JSONArray)jsonObject.get("entries");

JSONObject dataObject=(JSONObject) dataArray.get(0);

for(int i = 0; i < dataObject.size(); i++){
System.out.println("JSON Data is: " + dataObject.get("subscriptionId"));
System.out.println("JSON Data is: " + dataObject.get("subscriptionRefId"));

}

M
Replied on 25/08/2016

you can try something like this

http://stackoverflow.com/questions/29451914/how-to-extract-multiple-json-objects-into-string

tell me if this works.