Android Json Api Parsing
I have tried several tutorials using JSON parsing but I can't seem to make them work. Please can anyone kindly help and direct me to the right direction? I have now made some chang
Solution 1:
Json object may contain a number of key value pairs. In the jString posted in your question, strings like "searchTerm", "searchableLocations", etc are the String keys. The values could be anything like String, Int, Bollean, JSonArray, etc. Corresponding to the key "searchableLocations" the value is a JsonArray (denoted by [ ]).
JSONObject jObject = newJSONObject(jString);
String menuObject = jObject.getString("searchTerm");
JSONArray menuitemArray = jObject.getJSONArray("searchableLocations");
for (int i = 0; i < menuitemArray.length(); i++) {
JSONObject jsonObj = menuitemArray.getJSONObject(i);
String attributeId = jsonObj.getString("identifier");
System.out.println(attributeId);
String attributeValue = jsonObj.getString("name");
System.out.println(attributeValue);
}
String createDate = jObject.getString("jObject");
String result = jObject.getString("result");
Solution 2:
Does this code solve your problem?
Gson gson = new Gson();
MyClass obj = gson.fromJson(jString ,MyClass.class);
Post a Comment for "Android Json Api Parsing"