要解析的json数据如下:
/*请求结果-->{"result_count":10,"lastpg":10,"next_offset":1,"entry_list":[{"id":"4316","name_value_list":{"message":{"value":"u65b0u6587u53d1u8868uff1aAdministratoru5728u60a8u8d1fu8d23u7684u300eu4e0au6d77u9500u552eu90e8u6863u6848u300fu677fu5757u4e0b, u4e8e2013-11-07 18:11:23u53d1u8868u6587u7ae0u3010dsfsd u3011uff0cu8bf7u60a8u5173u6ce8u3002"},"sender":{"value":"System"},"recipient":{"value":"xiao"},"stamp":{"value":"2013-11-07 18:11"},"received":{"value":"0"},"parentid":{"value":"4316"}}},{"id":"4292","name_value_list":{"message":{"value":"u6587u7ae0u8bc4u8bbauff1au60a8u53d1u8868u5728u300eu4e0au6d77u9500u552eu90e8u6863u6848u300fu677fu5757u4e0bu7684u3010dsfsdfu3011u6587u7ae0uff0c u4e8e2013-11-05 18:12:55u88ab xiao u8bc4u8bbauff0cu8bf7u60a8u5173u6ce8u3002"},"sender":{"value":"System"},"recipient":{"value":"xiao"},"stamp":{"value":"2013-11-05 18:12"},"received":{"value":"0"},"parentid":{"value":"4292"}}},{"id":"4291","name_value_list":{"message":{"value":"u8bc4u8bbau5220u9664uff1au60a8u53d1u8868u5728u677fu5757u4e0bu7684u3010dsfsdfu3011u6587u7ae0u4e2du7684u8bc4u8bbauff0c u4e8e2013-11-05 18:12:14u88abxiaou5220u9664uff0cu8bf7u60a8u5173u6ce8u3002"},"sender":{"value":"System"},"recipient":{"value":"xiao"},"stamp":{"value":"2013-11-05 18:12"},"received":{"value":"0"},"parentid":{"value":"4291"}}}......*/
解析JSON数据格式
super.handleMessage(msg);
Bundle data = msg.getData();
String Result = data.getString("Result");//取得json数据
Log.i("mylog","请求结果-->" + Result);
JSONObject jsonObject;
try {
jsonObject = new JSONObject(Result);
JSONArray entry_list = jsonObject.getJSONArray("entry_list"); //取得json数组
lastpg = jsonObject.getInt("lastpg"); //取得json对象中的某个int数据
for (int i = 0; i < entry_list.length(); i++) {
JSONObject result = entry_list.getJSONObject(i);//取得json对象
Log.i("listlog",result.getString("id"));
String name_value_list = result.getString("name_value_list");//取得json对象中的某个String数据
jsonObject = new JSONObject(name_value_list);
JSONObject message = jsonObject.getJSONObject("message");
JSONObject sender = jsonObject.getJSONObject("sender");
JSONObject received = jsonObject.getJSONObject("received");
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("lvw_custom_name", sender.getString("value"));
map.put("lvw_custom_description", message.getString("value"));
map.put("received", received.getString("value"));
map.put("pm_id", result.getString("id"));
data1.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}