• android json解析


    https://www.bilibili.com/video/av22724233/?p=13

     一、解析json

    1.谷歌自带

    JSONObject

    try {
        JSONArray jsonArray = new JSONArray(result);
        JSONObject jsonObject=jsonArray.getJSONObject(0);
        mUserName=jsonObject.getString("USER_NAME");
        mRemark=jsonObject.getString("REMARK");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    opt对应的key不存在时返回null字符串或者指定值,get抛空指针异常

    jsonObject.optString("REMARK");

    2.GSON

    Gson gson = new Gson();
    //model要和json名称相同,model可以多于json的字段
    ModelList = gson.fromJson(json, new TypeToken<List<xxxModel>>() {}.getType());

    二、List转json

    1.GSON

                Gson gson=new Gson();
                String str=gson.toJson(models);

    三、GSONFormat插件

     

     alt+insert     选GsonFormat

    四、fastjson

    五、hijson小工具

  • 相关阅读:
    svn Mac
    webpack实用配置
    vuex状态管理-数据改变不刷新
    element-vue-koa2-mysql实现文件上传
    Promise的理解
    mysql Mac篇
    python 24 days
    python 7 days
    python 27 days
    python 26 days
  • 原文地址:https://www.cnblogs.com/buchizaodian/p/10112649.html
Copyright © 2020-2023  润新知