在JSONObject Android中创建所有键的数组 [英] create an array of all the keys in a JSONObject Android

查看:69
本文介绍了在JSONObject Android中创建所有键的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在JSONObject中创建所有键的数组.我的理解(如果我错了,请纠正我)是我需要将JSONObject转换为Map,然后从中创建一个数组,有人知道如何做到这一点吗?

Hi im wanting to create an array of all the keys in a JSONObject. my understanding (please correct me if i'm wrong) is that i need to convert the JSONObject to a Map and then create an Array from this does anyone know how to do this?

推荐答案

无需将 JSONObject 转换为Map,然后创建一个键数组,只需使用

No need to convert JSONObject to a Map and then create an Array of keys just use JSONObject.names() for getting all keys in an JsonArray then convert it to Array or ArrayList. example:

JSONObject  json = new JSONObject("json object string");
JSONArray namearray=json.names();  //<<< get all keys in JSONArray

这篇关于在JSONObject Android中创建所有键的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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