Guest User

Untitled

a guest
Sep 20th, 2018
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. protected void JSONparse(String result) {
  2. //parse JSON data
  3. try {
  4. JSONObject reader = new JSONObject(result);
  5. JSONObject head = reader.getJSONObject("feed").getJSONObject("entry").getJSONObject(result);
  6. JSONArray jArray = new JSONArray(head);
  7. for(int i=0; i < jArray.length(); i++) {
  8. JSONObject jObject = jArray.getJSONObject(i);
  9. String name = jObject.getString("name");
  10. String location = jObject.getString("location");
  11. String contact = jObject.getString("contact");
  12. Toast toast = Toast.makeText(this, name+" "+location+" "+contact, Toast.LENGTH_SHORT);
  13. toast.show();
  14.  
  15. } // End Loop
  16.  
  17. } catch (JSONException e) {
  18. Log.e("JSONException", "Error: " + e.toString());
  19. } // catch (JSONException e)
  20.  
  21. }
  22.  
  23. {"version":"1.0","encoding":"UTF-8",
  24. "feed":
  25. {"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$gsx":"http://schemas.google.com/spreadsheets/2006/extended","id":{"$t":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values"},"updated":{"$t":"2018-09-17T01:06:22.497Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],
  26. "title":{"type":"text","$t":"Sheet1"},"link":[{"rel":"alternate","type":"application/atom+xml","href":"https://docs.google.com/spreadsheets/d/"key"/pubhtml"},{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values"},{"rel":"http://schemas.google.com/g/2005#post","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values"},
  27. {"rel":"self","type":"application/atom+xml",
  28. "href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values?altu003djson"}],
  29. "author":[{"name":{"$t":"appsmedion"},"email":{"$t":"appsmedion@gmail.com"}}],"openSearch$totalResults":{"$t":"6"},"openSearch$startIndex":{"$t":"1"},
  30. "entry":
  31. [{"id":{"$t":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/cokwr"},
  32. "updated":{"$t":"2018-09-17T01:06:22.497Z"},
  33. "category":[{"scheme":"http://schemas.google.com/spreadsheets/2006",
  34. "term":"http://schemas.google.com/spreadsheets/2006#list"}],
  35. "title":{"type":"text","$t":"Chris knight "},
  36. "content":{"type":"text","$t":"location: Crows Nest NSW, type: dji, contact: na"},
  37. "link":[{"rel":"self","type":"application/atom+xml",
  38. "href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/cokwr"}],"gsx$name":{"$t":"Chris knight "},"gsx$location":{"$t":"Crows Nest NSW"},"gsx$type":{"$t":"dji"},
  39. "gsx$contact":{"$t":"na"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/cpzh4"},"updated":{"$t":"2018-09-17T01:06:22.497Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Shayne Johnston"},"content":{"type":"text","$t":"location: Hay Nsw , type: dji, contact: 466863944"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/cpzh4"}],"gsx$name":{"$t":"Shayne Johnston"},"gsx$location":{"$t":"Hay Nsw "},"gsx$type":{"$t":"dji"},"gsx$contact":{"$t":"466863944"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/cre1l"},"updated":{"$t":"2018-09-17T01:06:22.497Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Edward Morris"},"content":{"type":"text","$t":"location: Alkimos WA, type: dji, contact: edwardcmorris@yahoo.com.au"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/cre1l"}],"gsx$name":{"$t":"Edward Morris"},"gsx$location":{"$t":"Alkimos WA"},"gsx$type":{"$t":"dji"},"gsx$contact":{"$t":"edwardcmorris@yahoo.com.au"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/chk2m"},"updated":{"$t":"2018-09-17T01:06:22.497Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Andy"},"content":{"type":"text","$t":"location: Wellington St Mulgrave VIC, type: dji, contact: 413556955"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/chk2m"}],"gsx$name":{"$t":"Andy"},"gsx$location":{"$t":"Wellington St Mulgrave VIC"},"gsx$type":{"$t":"dji"},"gsx$contact":{"$t":"413556955"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/ciyn3"},"updated":{"$t":"2018-09-17T01:06:22.497Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Cody"},"content":{"type":"text","$t":"location: Alice Spring NT, type: parrot, contact: 412222222"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/ciyn3"}],"gsx$name":{"$t":"Cody"},"gsx$location":{"$t":"Alice Spring NT"},"gsx$type":{"$t":"parrot"},"gsx$contact":{"$t":"412222222"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/ckd7g"},"updated":{"$t":"2018-09-17T01:06:22.497Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Anthony "},"content":{"type":"text","$t":"location: Bundaberg , type: dji, contact: anthonycarrick1978@yahoo.com.au"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/"key"/od6/public/values/ckd7g"}],"gsx$name":{"$t":"Anthony "},"gsx$location":{"$t":"Bundaberg "},"gsx$type":{"$t":"dji"},"gsx$contact":{"$t":"anthonycarrick1978@yahoo.com.au"}}]}}
  40.  
  41. protected void JSONparse(String result) {
  42. //parse JSON data
  43. try {
  44. JSONObject reader = new JSONObject(result);
  45. JSONArray jArray = reader.getJSONObject("feed").getJSONArray("entry");
  46. for(int i=0; i < jArray.length(); i++) {
  47. JSONObject jObject = jArray.getJSONObject(i);
  48. String name = jObject.getString("gsx$name");
  49. String location = jObject.getString("gsx$location");
  50. String contact = jObject.getString("gsx$contact");
  51. Toast toast = Toast.makeText(this, name+" "+location+" "+contact, Toast.LENGTH_SHORT);
  52. toast.show();
  53.  
  54. } // End Loop
  55.  
  56. } catch (JSONException e) {
  57. Log.e("JSONException", "Error: " + e.toString());
  58. } // catch (JSONException e)
  59.  
  60. }
Add Comment
Please, Sign In to add comment