Presentation is loading. Please wait.

Presentation is loading. Please wait.

JSON Android Club 2015.

Similar presentations


Presentation on theme: "JSON Android Club 2015."— Presentation transcript:

1 JSON Android Club 2015

2 Agenda JSON Parsing ListView

3 What is JSON? JavaScript Object Notation Minimal Readable format
Server <-> Client Alternative to XML Language independant

4 JSON object: example { "id": 9999, "firstName": "Joe", "lastName": "Richard“ }

5 JSON object: practice Create object for one book: author: Haruki Murakami title: Norwegian Wood year: 1987 You can check JSON in

6 JSON array: example { "employees": [ "firstName": "Joe", "lastName": "Richard" }, "firstName": "Anna", "lastName": "Kim" "firstName": "Kain", "lastName": "Saridzawa" } ]

7 JSON array: practice Create array: students Add three students:
Each student should contain 1) id 2) first_name 3) last_name

8 JSON symbols { object } [ array ] : equals “variable/object name”
“String” int

9 JSON parsing: example http://joerichard.net/api/ac/student.json
JSONObject object = new JSONObject(s); String id = object.getString("id"); MainActivity.tvData.setText("My id is "+id);

10 JSON parsing: practice
Parse JSON object Take its ip Message: “My ip is ”

11 JSON object parsing: example
Create Student POJO It should include: id, first_name, last_name Create JSON object to Student object

12 JSON object parsing: practice
Create POJO: JsonIP It should have: ip, about, Pro! Convert JSON Object to JsonIP object

13 JSON array: example JSONObject object = new JSONObject(s); JSONArray employees = object.getJSONArray("employees"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < employees.length(); i++) { JSONObject employee = employees.getJSONObject(i); String firstName = employee.getString("firstName"); String lastName = employee.getString("lastName"); sb.append(firstName+" "+lastName+"\n"); } MainActivity.tvData.setText(sb.toString());

14 JSON array: practice http://joerichard.net/api/ac/tariffs.json
Show list of tarrifs

15 JSON array ->Object list: example
Create POJO: Employee It should include: firstName, lastName Convert JSON array to Object list Show amount of list items

16 JSON array -> POJO list: practice
Create POJO: Tariff It should contain: id, name Convert JSON array to Tariff list Show size of list

17 Homework http://joerichard.net/api/tw/tw.json
Take data from Object->daily->data array Show weather data in TextView in this form c-34c c-40c … like this for 7 days

18 Questions? Any questions?

19 Thank you Thank you for your attention!


Download ppt "JSON Android Club 2015."

Similar presentations


Ads by Google