Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create an array of all the keys in a JSONObject Android

Tags:

android

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?

like image 532
Luke Batley Avatar asked Dec 08 '22 17:12

Luke Batley


1 Answers

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
like image 194
ρяσѕρєя K Avatar answered Dec 11 '22 11:12

ρяσѕρєя K