如何将 JSONArray 转换为 JSONObject? [英] How can I turn a JSONArray into a JSONObject?

查看:217
本文介绍了如何将 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 ,里面有相同的信息.这样我就可以传递对象,然后当我想要时,我可以从对象中获取所有信息.任何帮助将不胜感激,谢谢.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆