Avatar of Zolf
Zolf
Flag for United Arab Emirates asked on

Parse JSON data

Hello there,

How get the response from the server with a list of objects. Now I want to know how can I get some part of the data on my client side. My JSON looks like this

{"productId":{
"isImported":false, "routeOfAdminId":null, "manufacturerId":null, "shelfDate":null, "dosagePackageTypeId":null, "genericname":null, "packageQty":null, "brandName":"Coar", "updatedBy":null, "id":5, "created":1385270765983, 
"productPackage":{"widthunit":null, "depthunit":null, "weight":null, "heightunit":null, "packageTypeByPackagingunit":null, "weightunit":null, "width":null, "qty":null, "depth":null, "id":5, "packageTypeByQtyunit":null, "height":null, "packaging":null}, 
"supplierId":{"phone":null, "fax":null, "suppliersince":null, "status":false, "perName":"Ba Per", "lastUpdated":1384580197033, "web":null, "postcode":null, "companycode":null, "section":{"id":1, "createdBy":1, "created":1369838095000, "name":"Medical", "lastUpdated":null, "code":1, "alternateName":"a", "updatedBy":1}, "updatedBy":1, "personincharge":null, "city":{"id":311, "telcode":21, "cityname":"?????", 
"district":{"id":531, "districtname":"?????", "countyId":{"id":113, "countyname":"?????", "province":{"id":8, "provincename":"?????", "code":10, "capital":"?????"}}}, "taxcode":1001000}, "id":1, "companyid":null, "createdBy":1, "address":"dsfadfadf", "created":1384579329223, "email":null, 
"contractId":{"id":1, "contractTo":1416116154000, 
"contractTp":{"id":1, "engname":"Credit", "pername":"Credit Per", 
"contractSs":[null,{"id":4, "contractTo":1417333515000, "contractTp":null, "contractNo":77, "contractFrom":1385797515000},{"id":3, "contractTo":1416633147000, "contractTp":null, "contractNo":122, "contractFrom":1385097146000}]}, "contractNo":1222, "contractFrom":1384580154000}, "supplierid":1, "printName":null, "engName":"Ba"}, "status":null, "productCode":5, "dosage":null, "barcode":null, "lastUpdated":null, "printname":null, "dosageFormId":null, "packageQtyPackageTypeId":null, 
"sectionId":{"id":1, "createdBy":1, "created":1369838095000, "name":"Medical", "lastUpdated":null, "code":1, "alternateName":"a", "updatedBy":1}, "createdBy":1, "irc":null, "fdocode":null, "productCategoryId":null, "storage":null}, "id":9, "purchasePrice":8000, "_selection_35":true, "orderQty":7500}

Open in new window



now I when I do this(see below code) I get result of some values but some are retuning null( the LISTGRID RECORD  2   and LISTGRID RECORD  3 are NULL). what am I doing wrong

Record getQty = orderGrid.getEditedRecord(i);
JavaScriptObject jsObj = getQty.getJsObj();
			
JSONObject o = new JSONObject(jsObj);
			
System.out.println("LISTGRID RECORD   1  "+o.toString());
			
System.out.println("LISTGRID RECORD  2   "+o.get("section"));           //RETURNING NULL
			
System.out.println("LISTGRID RECORD   3  "+o.get("supplierId"));      //RETURNING NULL
			
System.out.println("LISTGRID RECORD   4  "+o.get("productId"));       
			
System.out.println("PRODUCT QTY    "+o.get("id")+"  PRODUCT QTY    "+o.get("orderQty"));  // PRODUCT QTY    9  PRODUCT QTY    7500

Open in new window

JavaJava EEJavaScript

Avatar of undefined
Last Comment
Zolf

8/22/2022 - Mon
Manish

JSONObject newObject = (JSONObject) o.get("productId");
      System.out.println((JSONObject)newObject.get("sectionId"));
ASKER CERTIFIED SOLUTION
Manish

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Zolf

ASKER
thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy