create an array of all the keys in a JSONObject Android

后端 未结 3 1151
执念已碎
执念已碎 2021-01-19 19:38

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 th

3条回答
  •  感动是毒
    2021-01-19 20:06

    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
    

提交回复
热议问题