Advertisement
Guest User

JSON Parser

a guest
Mar 2nd, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import org.json.*;
  2.  
  3. public class routeParser{
  4.  
  5. private JSONObject routeString;
  6. private JSONArray instructions;
  7. private String distance;
  8. private String eta;
  9. private String points;
  10. private String[][] route;
  11.  
  12.  
  13. public routeParser(String route) throws Exception{
  14. this.routeString = new JSONObject(route);
  15. this.distance = routeString.getString("distance");
  16. this.eta = routeString.getString("time");
  17. JSONArray temp = routeString.getJSONArray("paths");
  18. this.instructions = temp.getJSONArray(2);
  19. this.points = temp.getString(5);
  20. }
  21. public void parseRoute() throws Exception{
  22. route = new String[instructions.length()][3];
  23. for (int i = 0; i < instructions.length(); i++)
  24. {
  25. route[i][0] = instructions.getJSONObject(i).getString("text");
  26. route[i][1] = (String)instructions.getJSONObject(i).getString("time");
  27. route[i][2] = (String)instructions.getJSONObject(i).getString("distance");
  28. }
  29. }
  30.  
  31. public String getDistance(){
  32. return distance;
  33. }
  34. public String getPoints(){
  35. return points;
  36. }
  37. public String getETA(){
  38. return eta;
  39. }
  40. public String[][] getRoute(){
  41. return route;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement