-1
如何計算JSON對象中有多少個對象 我的代碼是計數JSON節點
String json = IOUtils.toString(is);
JSONObject jo = new JSONObject(json);
這裏「JO」,與在該對象的jsonobeject某些數據有沒有數據:
{
"cargoDetails":[{
"noOfPackages":"2",
"packType":"AUG",
"uom":"LB",
"packLength":"10",
"actualWt":"5",
"packHeight":"2",
"packWidth":"4",
"packDescription":"description",
"currId":"1",
"shipmentMode":"1"},
{"noOfPackages":"2",
"packType":"BAG",
"uom":"KG",
"packLength":"10",
"actualWt":"5",
"packHeight":"2",
"packWidth":"4",
"packDescription":"description",
"currId":"1",
"shipmentMode":"1"}],
"type":"air",
"userId":"KOTESWAR",
"customerId":"CUST00168",
"contractId":"CONTRACT0000576",
"originTerminalId":"FINBOM",
"destinationTerminalId":"FINDEL",
"ShipperId":"CUST00003",
"serviceLevelId":"STD",
"paymentTerms":"Prepaid",
"terminalId":"FINBOM",
"originDepartment":"AE",
"destinationDepartment":"AI",
"departurePort":"INBOM",
"destinationPort":"BOM",
"totalNoPcs":"4",
"totalActualWt":"5",
"totalVol":"10"
}
k與在我可以發送cargodetails對象2剩餘的是預訂詳細信息 所以我的問題是如何找到有多少對象在jO。 ,因爲只有我可以迭代循環。