Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. package pl.wsb.zpam.laboratorium3.ztm.parser;
  2. import org.json.JSONException;
  3. import org.json.JSONObject;
  4. import pl.wsb.zpam.laboratorium3.demo.json.model.Person;
  5. import pl.wsb.zpam.laboratorium3.ztm.model.TimeItem;
  6. public class TimeItemJsonParser
  7. {
  8. public TimeItem parse(String json) throws JSONException
  9. {
  10. JSONObject jsonObject = new JSONObject(json);
  11. return parse(jsonObject);
  12. }
  13. public TimeItem parse(JSONObject jsonObject)
  14. {
  15. TimeItem timeItem = new TimeItem();
  16. // TODO! Zadanie 3.1 - zaimplementowac parsowanie JSON reprezentujacego pojedynczy wpis na rozkladzie jazdy ZTM
  17. // Na potrzeby tego zadania nalezy obslugiwac nastepujace pola JSONa:
  18. // * routeId
  19. // * estimatedTime
  20. // * headsign
  21. // Przykladowy plik JSON zawierajacy pojedynczy wpis: SampleTimeItem.json
  22. // Przykladowy kod parsujacy pojedyncza wlasciwosc obiiektu JSON
  23. // int delayInSeconds = jsonObject.optInt("delayInSeconds");
  24. // timeItem.setDelayInSeconds(delayInSeconds);
  25. int estimatedTime = jsonObject.optInt("estimatedTime");
  26. String headsign = jsonObject.optString("headsign");
  27. int routeid = jsonObject.optInt("routeid");
  28. return TimeItem(estimatedTime, headsign, routeid);
  29. }
  30. }
  31.  
  32. timeitemjsonparser
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement