Im doing a dynamic form to Android and I need just read a Json file and build a form and it should work in anyway. How can I do it? In "name" getString("name") what I can put there to get a name without write "name" inside de method?
-
Can you include a sample of your code?Anna Billstrom– Anna Billstrom2015-06-17 17:18:01 +00:00Commented Jun 17, 2015 at 17:18
-
I just need to get a String without to write strings name. eg: getString("name") -> getString( the index of JsonObject)daniel12345smith– daniel12345smith2015-06-17 17:25:11 +00:00Commented Jun 17, 2015 at 17:25
-
I guess you could get the index of the key- if you went through the step of getting all keys into an array. But that seems laborious.Anna Billstrom– Anna Billstrom2015-08-24 16:36:52 +00:00Commented Aug 24, 2015 at 16:36
2 Answers
Is the question that you want to find the keys of a JSONArray? Iterate through the array, grab the key of each object. Then, grab the value.
See second answer: Retrieving Keys from JSON Array key-value pair dynamically - Javascript
Comments
I think the following should help:
http://developer.android.com/reference/org/json/JSONObject.html#keys()
You can use this Iterator to iterate through all the keys and then use the key to extract the desired values.
Additionally, if dealing with a JSONArray you could use the following too: http://developer.android.com/reference/org/json/JSONObject.html#names()