【蜕变之路】第44天 Map、JSONObject、JSONArray的转换(2019年9月1日)

    Hello,大家好!我是程序员阿飞!今天主要给大家分享一下Java中Map、JSONObject、JSONArray之间的转换,好了,我们直奔主题吧!  

    1、Map转JSONObject对象

          JSONObject jsonObject = JSONObject.fromObject(params);//import net.sf.json.JSONObject;

    2、Map转JSONArray数组

          JSONArray jsonArray= JSONArray.fromObject(paramsMap);//import net.sf.json.JSONArray;

    3、获取JSONObject的值

          String taskCode = jsonObject.get("taskCode").toString();

          String code = jsonObject.getString("code");

    4、Json字符串转JSONObject对象

          JSONObject jsonObject = JSONObject.fromObject(result);

    5、判断JSONObject是否为空

          !jsonObject.isNullObject()

    6、Json字符串转JSONArray数组

          JSONArray data = parseArray(datas.get("data").toString());

    7、一个项目请求另一个项目的方法

          result = HttpRequest.post(newUrl).timeout(3000).form(params).execute().body();



猜你喜欢

转载自blog.51cto.com/12388374/2434162