zoukankan      html  css  js  c++  java
  • java解析json格式数据

    要解析的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();
    }
    

      

  • 相关阅读:
    B
    A
    I
    IIS发布和部署
    编程中什么叫上下文
    浅谈Session,Cookie和http协议中的无状态
    cmd界面输入sqlplus提示不是内外部命令解决方法
    C#已设置安全调试选项,但此选项要求的VS承载进程在此调试中不可用。解决方法
    IIS和IIS Express的区别
    vue.js:634 [Vue warn]: Failed to generate render function: SyntaxError: Unexpected token ')'
  • 原文地址:https://www.cnblogs.com/flowers-yang/p/3388738.html
Copyright © 2011-2022 走看看