Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Parse JSON data

Posted on 2013-12-01
3
Medium Priority
?
369 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
ID: 39689334
JSONObject newObject = (JSONObject) o.get("productId");
      System.out.println((JSONObject)newObject.get("sectionId"));
0
 
LVL 11

Accepted Solution

by:
Manish earned 2000 total points
ID: 39689339
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
ID: 39689413
thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

916 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