【蛻變之路】第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();



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章