1 00:00:00,300 --> 00:00:02,800 Welcome back, how did you do? 2 00:00:02,800 --> 00:00:05,160 Hopefully this is just review for you. 3 00:00:05,160 --> 00:00:08,641 We start off here creating a new array of hour objects. 4 00:00:12,006 --> 00:00:13,479 So Hour array. 5 00:00:15,585 --> 00:00:19,441 We'll call it hours, so new_Hour array, 6 00:00:22,885 --> 00:00:28,045 Data.length. 7 00:00:28,045 --> 00:00:31,717 We can then loop through all the items in the JSON array, 8 00:00:31,717 --> 00:00:37,870 get the data we want from each one, and set a new Hour object in the hours array. 9 00:00:37,870 --> 00:00:39,010 I'll do it in a for loop. 10 00:00:40,010 --> 00:00:42,781 Scroll up here a little bit, give ourselves some room. 11 00:00:45,177 --> 00:00:46,608 So for. 12 00:00:51,061 --> 00:00:54,777 So as long as i is less than the length of our data. 13 00:00:57,818 --> 00:00:58,730 Our incrementor. 14 00:01:00,610 --> 00:01:06,020 One thing to note here is that length is a method, not a property. 15 00:01:06,020 --> 00:01:10,280 With a normal array, like our array of hours, 16 00:01:10,280 --> 00:01:14,390 we get the length via a property called length, not a method. 17 00:01:15,420 --> 00:01:20,340 It's easy to confuse the two, but that's why we have auto-complete. 18 00:01:20,340 --> 00:01:21,590 Back to our loop. 19 00:01:21,590 --> 00:01:26,640 Our first step is to create a new JSON object for the item at position i. 20 00:01:26,640 --> 00:01:31,572 So JSONObject, we'll call it 21 00:01:31,572 --> 00:01:35,745 jsonHour, we want data, 22 00:01:35,745 --> 00:01:40,687 getJSONObject at position i. 23 00:01:42,711 --> 00:01:45,095 Now we create an hour object, 24 00:01:50,599 --> 00:01:54,571 And set our values from the JSON. 25 00:01:54,571 --> 00:01:58,981 So setSummary(jsonHour). 26 00:02:01,017 --> 00:02:05,286 GetString, and it was called summary. 27 00:02:08,849 --> 00:02:10,768 We'll set our icon. 28 00:02:14,263 --> 00:02:15,888 Again, that was a string. 29 00:02:21,151 --> 00:02:26,767 We'll set our temperature, which is a double. 30 00:02:32,848 --> 00:02:35,654 Called temperature. 31 00:02:35,654 --> 00:02:42,266 We'll set our time, Which was a long, 32 00:02:47,416 --> 00:02:48,733 Called "time". 33 00:02:50,610 --> 00:02:55,234 And we'll set our timezone. 34 00:02:55,234 --> 00:02:57,059 We'll pass in timezone. 35 00:03:05,648 --> 00:03:07,798 And now we can return hours. 36 00:03:11,020 --> 00:03:14,620 All right, let's verify this is working by using the debugger. 37 00:03:15,670 --> 00:03:18,880 We can set a break point here where we're defining hour. 38 00:03:19,930 --> 00:03:23,684 Set a break point, and we run our app with the debugger. 39 00:03:44,303 --> 00:03:45,722 There's our hour. 40 00:03:49,713 --> 00:03:52,040 And we see it starts populating. 41 00:03:52,040 --> 00:03:52,900 Very nice. 42 00:03:52,900 --> 00:03:54,729 And our data is coming through. 43 00:03:54,729 --> 00:03:59,116 Terrific, let's not forget to remove this break point before we move on. 44 00:04:05,600 --> 00:04:07,235 Fantastic work. 45 00:04:07,235 --> 00:04:11,080 We've updated our data model to handle this more complex set of data, and 46 00:04:11,080 --> 00:04:16,570 then we saw how to use the JSON array class to work with arrays of JSON objects. 47 00:04:16,570 --> 00:04:20,700 With this skill set, you are pretty much a master of working with JSON in Android. 48 00:04:21,810 --> 00:04:23,827 It can get a little tedious though. 49 00:04:23,827 --> 00:04:27,845 In true Android and open source fashion, there are some excellent 50 00:04:27,845 --> 00:04:32,545 third party libraries available that make working with json data even easier. 51 00:04:32,545 --> 00:04:35,535 If you're interested, check out the links in the teacher's notes.