0

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?

3
  • Can you include a sample of your code? Commented 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) Commented 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. Commented Aug 24, 2015 at 16:36

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.