如何将JSONArray转换为JSONObject? [英] How can I turn a JSONArray into a JSONObject?
本文介绍了如何将JSONArray转换为JSONObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上我有:
JSONArray j = new JSONArray();
j.add(new JSONObject()); //JSONObject has a bunch of data in it
j.add(new JSONArray()); //JSONArray has a bunch of data in it
现在我想把它变成 JSONArray
进入 JSONObject
,其中包含相同的信息。这样我就可以传递Object然后当我想要时我可以从对象中获取所有信息。任何帮助将不胜感激,谢谢。
And now I would like to turn that JSONArray
into a JSONObject
with the same information in it. So that I can pass around the Object and then when I want I can grab all the information out of the object. Any help would be appreciated, Thanks.
推荐答案
通常,Json对象将包含您的值(包括数组)作为命名字段。所以,比如:
Typically, a Json object would contain your values (including arrays) as named fields within. So, something like:
JSONObject jo = new JSONObject();
JSONArray ja = new JSONArray();
// populate the array
jo.put("arrayName",ja);
JSON中的哪一个是{arrayName:[...]}。
Which in JSON will be {"arrayName":[...]}.
这篇关于如何将JSONArray转换为JSONObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文