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.
Asked
Active
Viewed 816 times
0
-
is it a valid json http://jsonlint.com/?? – Raghunandan Apr 09 '15 at 09:21
-
Can we see your latest attempt? Have you retrieved the JSON from the XML to start with? I doubt it will parse correctly with the `
` tag around it. – halfer Apr 09 '15 at 09:25 -
yes it is a valid json, i tried of parsing it using the following code – Sai Chakradhar Sana Apr 09 '15 at 09:26
-
JSONObject obj = new JSONObject(response); – Sai Chakradhar Sana Apr 09 '15 at 09:26
-
1this is not valid json, it gives error here "@is_active":"True",Adam" – Heshan Sandeepa Apr 09 '15 at 09:47
-
This isn't a valid json – surhidamatya Apr 09 '15 at 09:48
-
Its not a valid JSON. – Narendra Apr 09 '15 at 10:13
2 Answers
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
-
it is throwing a JSON Exception as, value ... of type java.lang.string cannot be converted to JSONObject. I think we need to convert the response to string before parsing it. Did you get my point. Thanks – Sai Chakradhar Sana Apr 09 '15 at 10:17
-
in above code "json" is the value you get from server so if it's json then you don't need this line String json = getJSONFromServer(); – surhidamatya Apr 09 '15 at 11:00
-
could you please elaborate your answer i couldnt get you @sur007 – Sai Chakradhar Sana Apr 09 '15 at 14:41
-
Sorry, This is not working @sur007. Throwing exception. JSONException: java.lang.string cannot be converted to JSONObject. – Sai Chakradhar Sana Apr 10 '15 at 08:52
-
@SaiChakradharSana can you post the question with implemented code – surhidamatya Apr 10 '15 at 08: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.]

i_am_sedated
- 1
- 2