Solved

Parse JSON data

Posted on 2013-12-01
3
330 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 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Initialize SharePoint Online List Values in Quick Edit 7 20
table example 4 20
Javascript and Jquery not firing 9 37
insert text field data into html script 13 21
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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 about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

919 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

19 Experts available now in Live!

Get 1:1 Help Now