Can I get value from JSONObject without mention its name?

java, json, org.json

Solution

You can call `names()` on a `JSONObject` to get a `JSONArray` of the names of its elements - this would let you do logic on them or retrieve their corresponding values dynamically.

Problem

My JSONObject: ``` {MyJSON:[{"id":"1","name":"panji","price":"100"}]} ``` I do this to get value of id: ``` menuitemArray.getJSONObject(i).getString("id"); ``` Can I get the value of id, name or price, without mentioning its name, may be like index or another method?

Original source