Solved

Parse JSON data

Posted on 2013-12-01
3
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Node.js 11 82
15 puzzle in Javascript/html 2 90
using executorService 3 24
Convert complicated date to yyyy-mm-dd format 22 53
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 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