Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{"category_name":"Food","filter_type":"Sort by","field_name":"","type":"VALUE","table_name":"","item_list":["Ascending","Descending"]}
- if (jsonStr != null) {
- try {
- foods = new JSONArray(jsonStr);
- // looping through All Contacts
- for (int i = 0; i < foods.length(); i++) {
- JSONObject c = foods.getJSONObject(i);
- if(c.getString("category_name").equals("Food")) {
- String category_name = c.getString(TAG_CATEGORY_NAME);
- String table_name = c.getString(TAG_TABLE_NAME);
- String item_list = c.getString(TAG_ITEM_LIST);
- // tmp hashmap for single contact
- HashMap<String, String> contact = new HashMap<String, String>();
- // adding each child node to HashMap key => value
- contact.put(TAG_CATEGORY_NAME, category_name);
- contact.put(TAG_TABLE_NAME, table_name);
- contact.put(TAG_ITEM_LIST, item_list);
- // adding contact to contact list
- foodlistfilter.add(contact);
- }
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- }
- String str = "[{"category_name":"Food","filter_type":"Sort by","field_name":"","type":"VALUE","table_name":"","item_list":["Ascending","Descending"]}";
- JSONArray jsonArray = new JSONArray(str);
- //now it holds the JSONObject.
- for (int i = 0; i<= jsonArray.length(); i++) {
- //now we loop through and get the jsonObject
- JSONObject jsonObj = new JSONObject(jsonArray.getJsonObject(i));
- //now it contains your data.
- Log.d("Category_nameValue=", jsonObj.getString("category_name"));
- //now we want to get the array from the item_list.
- JSONArray itemList = new JSONArray(jsonObj.getString("item_list"));
- //now itemList.getString(1); === Ascending while itemList.getString(2) == Descending
- //now itemList contains several new objects which can also be looped as the parent one.
- }
- JSONArray itemList = c.getJSONArray(name)
- for (int i = 0; i < itemList.length(); i++) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement