Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. [{"category_name":"Food","filter_type":"Sort by","field_name":"","type":"VALUE","table_name":"","item_list":["Ascending","Descending"]}
  2.  
  3. if (jsonStr != null) {
  4. try {
  5.  
  6. foods = new JSONArray(jsonStr);
  7.  
  8.  
  9. // looping through All Contacts
  10. for (int i = 0; i < foods.length(); i++) {
  11. JSONObject c = foods.getJSONObject(i);
  12.  
  13. if(c.getString("category_name").equals("Food")) {
  14.  
  15. String category_name = c.getString(TAG_CATEGORY_NAME);
  16. String table_name = c.getString(TAG_TABLE_NAME);
  17. String item_list = c.getString(TAG_ITEM_LIST);
  18.  
  19. // tmp hashmap for single contact
  20. HashMap<String, String> contact = new HashMap<String, String>();
  21.  
  22. // adding each child node to HashMap key => value
  23. contact.put(TAG_CATEGORY_NAME, category_name);
  24. contact.put(TAG_TABLE_NAME, table_name);
  25. contact.put(TAG_ITEM_LIST, item_list);
  26.  
  27. // adding contact to contact list
  28. foodlistfilter.add(contact);
  29.  
  30. }
  31. }
  32. } catch (JSONException e) {
  33. e.printStackTrace();
  34. }
  35. } else {
  36. Log.e("ServiceHandler", "Couldn't get any data from the url");
  37. }
  38.  
  39. String str = "[{"category_name":"Food","filter_type":"Sort by","field_name":"","type":"VALUE","table_name":"","item_list":["Ascending","Descending"]}";
  40.  
  41. JSONArray jsonArray = new JSONArray(str);
  42. //now it holds the JSONObject.
  43. for (int i = 0; i<= jsonArray.length(); i++) {
  44. //now we loop through and get the jsonObject
  45. JSONObject jsonObj = new JSONObject(jsonArray.getJsonObject(i));
  46. //now it contains your data.
  47. Log.d("Category_nameValue=", jsonObj.getString("category_name"));
  48. //now we want to get the array from the item_list.
  49. JSONArray itemList = new JSONArray(jsonObj.getString("item_list"));
  50. //now itemList.getString(1); === Ascending while itemList.getString(2) == Descending
  51.  
  52.  
  53.  
  54. //now itemList contains several new objects which can also be looped as the parent one.
  55. }
  56.  
  57. JSONArray itemList = c.getJSONArray(name)
  58. for (int i = 0; i < itemList.length(); i++) {
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement