0

I am new to android. I am currently working on an enterprise application. In this application i am working with restful web services. But i want to know different types of parsing techniques in retrieving the data from a source.

2 Answers2

3

At first check if it's valid json. If it's then at first you'll need to parse XML then parse json from the result and parse that json.

Json parsing way is answered here

Try this way. It might help

// Get some JSON from wherever
String json = getJSONFromServer();

where json =  {"EngProjects":{"ENG":[{"@trouble_id":"289302","@resolution_id":"","@is_active":"True","@CSM":"","@subject":"Test","@owner_user_id":"23","@trouble_issue_desc":"Account Team Document","@Age":"5","@Stage":"In Queue","@Severity":"Low","@due_dtm":"","@next_step":"","@add_dtm":"4/3/2015 1:16:02 PM","@closed_dtm":"","@comment":"","@issue_id":"769","@notes_count":"0"},{"@trouble_id":"271080","@resolution_id":"","@is_active":"True","@CSM":"","@subject":"Tew","@owner_user_id":"6","@trouble_issue_desc":"Customer Carrier Portals and Logins","@Age":"315","@Stage":"Researching","@Severity":"Medium","@due_dtm":"11/17/2014","@next_step":"adsadsf","@add_dtm":"5/28/2014 9:09:18 AM","@closed_dtm":"","@comment":"adfadfasdfd","@issue_id":"780","@notes_count":"0"}]}} 

 // Parse the JSON response into an object
 JSONObject object = new JSONObject(json);

 // Get the results array
 JSONArray users = object.getJSONArray("ENG");
 for(int i = 0; i < users.length(); i++) {
 // Each element in the results array is a JSONObject with a single
 // property "user" which is a JSONObject that contains the user data
 JSONObject user = users.getJSONObject(i).getJSONObject("user");

 Log.e(TAG, user );
}
Community
  • 1
  • 1
surhidamatya
  • 2,419
  • 32
  • 56
0

Maybe you can try to parse the xml, and check this on different method to use xml parse http://developer.android.com/training/basics/network-ops/xml.html

Then, once you get the value. You can use the JSONObject to parse the json.

[I tried with jsonlint and it is not a valid json. But if it requires that you need to parse it. Parse the xml part then get the json.]