要解析的json数据如下:
/*请求结果-->{"result_count":10,"lastpg":10,"next_offset":1,"entry_list":[{"id":"4316","name_value_list":{"message":{"value":"\u65b0\u6587\u53d1\u8868\uff1aAdministrator\u5728\u60a8\u8d1f\u8d23\u7684\u300e\u4e0a\u6d77\u9500\u552e\u90e8\u6863\u6848\u300f\u677f\u5757\u4e0b,\t\u4e8e2013-11-07 18:11:23\u53d1\u8868\u6587\u7ae0\u3010dsfsd \u3011\uff0c\u8bf7\u60a8\u5173\u6ce8\u3002"},"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":"\u6587\u7ae0\u8bc4\u8bba\uff1a\u60a8\u53d1\u8868\u5728\u300e\u4e0a\u6d77\u9500\u552e\u90e8\u6863\u6848\u300f\u677f\u5757\u4e0b\u7684\u3010dsfsdf\u3011\u6587\u7ae0\uff0c\t\u4e8e2013-11-05 18:12:55\u88ab xiao \u8bc4\u8bba\uff0c\u8bf7\u60a8\u5173\u6ce8\u3002"},"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":"\u8bc4\u8bba\u5220\u9664\uff1a\u60a8\u53d1\u8868\u5728\u677f\u5757\u4e0b\u7684\u3010dsfsdf\u3011\u6587\u7ae0\u4e2d\u7684\u8bc4\u8bba\uff0c\t\u4e8e2013-11-05 18:12:14\u88abxiao\u5220\u9664\uff0c\u8bf7\u60a8\u5173\u6ce8\u3002"},"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 map = new HashMap();
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();
}