我是android新手。我目前正在研究企业应用程序。在这个应用程序中,我正在使用restful Web服务。但我想知道从源检索数据时不同类型的解析技术。
答案 0 :(得分:3)
首先检查它是否是有效的json。如果是,那么一开始你需要解析XML然后从结果中解析json并解析那个json。
Json解析方式已回答here
试试这种方式。这可能会有所帮助
// 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 );
}
答案 1 :(得分:0)
也许你可以尝试解析xml,并在不同的方法上检查这个以使用xml解析http://developer.android.com/training/basics/network-ops/xml.html
然后,一旦你得到了价值。您可以使用JSONObject来解析json。
[我尝试使用jsonlint,它不是一个有效的json。但如果需要你需要解析它。解析xml部分然后获取json。]