converting JSON OBJECT to JSON ARRAY

后端 未结 2 1253
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 08:14

This is very simple one but struggeling. help me out of this.

I am having a json data { \"abc\":\"test\",\"bed\":\"cot\",\"help\":\"me\"}

I want to convert a

相关标签:
2条回答
  • 2021-01-16 08:33

    Directly put JsonObject i.e. obj into jsonArray

    jsonArray.put(obj);
    //result is [{ "abc":"test","bed":"cot","help":"me"}]
    

    Final code

    JSONObject obj= new JSONObject(str);
    JSONArray jsonArray = new JSONArray();
    //simply put obj into jsonArray
    jsonArray.put(obj);
    //result is [{ "abc":"test","bed":"cot","help":"me"}]
    
    0 讨论(0)
  • 2021-01-16 08:49

    It works for me.

    JSONObject obj = new JSONObject(result.toString()); JSONArray arr = obj.getJSONArray("value");

    0 讨论(0)
提交回复
热议问题