Solved

Parse JSON data

Posted on 2013-12-01
3
326 Views
Last Modified: 2013-12-02
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

0
Comment
Question by:zolf
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Manish
Comment Utility
JSONObject newObject = (JSONObject) o.get("productId");
      System.out.println((JSONObject)newObject.get("sectionId"));
0
 
LVL 11

Accepted Solution

by:
Manish earned 500 total points
Comment Utility
System.out.println((JSONObject)newObject.get("supplierId"));

Format your json at
http://jsonformatter.curiousconcept.com/ so that structure will be clear to you.
0
 

Author Closing Comment

by:zolf
Comment Utility
thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This article discusses how to create an extensible mechanism for linked drop downs.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now