记录json解析

来源:互联网 发布:馆陶县行知教育集团 编辑:程序博客网 时间:2024/06/06 02:58
 一...
 1. 使用jsonObject的时候需要注意.如果返回的json本身就是数组.则需要使用jsonArray,大括号属于对象,中括号属于数组
    String jsonString ="{\"name\":\"zhangsan\",\"password\":\"zhangsan123\",\"email\":\"10371443@qq.com\"}";




"body": {
"datalist": [{
"fundchinesenm": "东海东风1号"
"aptm": "15:00:00"
"fee": "123.00"
},

{
"fundchinesenm": "东海东风1号",
"aptm": "150000",
"fee": "123.00",
}],
}


 2.jsonObject的基本用法 JSONObject mjson = new JSONObject(jsonString);  
string name = mjson.getString("name");


 3.jsonObjectArray的基本用法 JSONObject mjson = new JSONObject("body"); //获取到json对象
     JSONObjectArray mArray = mjson.getJSONArray("datalist"); //获取到数组
     for(int i = 0;i = mArray.length();i++){
         JSONObject mjo = mArray.getJSONObject(i);//获取到数组json里面的对应的值
String fundchinesenm = mjo.getString("fundchinesenm"); //取到值
};


  二...
 1. 使用gson解析数据.非常的简单,
    Gson gson = new Gson();
    Result result = gson.fromJson(jsonData, Result.class);

 
原创粉丝点击