1 00:00:00,140 --> 00:00:05,240 We've seen how to access our JSON weather data and parse single field data. 2 00:00:05,240 --> 00:00:11,210 Next, let's look at how we can drill down and get data inside a nested JSON object. 3 00:00:11,210 --> 00:00:15,632 For our Stormy app, we want to get data inside the currently key, seen here. 4 00:00:17,897 --> 00:00:20,170 Why don't you give it a try yourself? 5 00:00:20,170 --> 00:00:23,184 Pause me, write it out, and come back and see how you did. 6 00:00:27,150 --> 00:00:30,223 Let's declare a new JSONObject variable. 7 00:00:30,223 --> 00:00:31,710 So we can put it down here. 8 00:00:35,114 --> 00:00:36,153 We'll call it currently. 9 00:00:39,712 --> 00:00:42,596 It's equal to forecast. 10 00:00:44,593 --> 00:00:50,792 We'll getJSONObject ("currently"). 11 00:00:50,792 --> 00:00:53,200 How did you do? 12 00:00:53,200 --> 00:00:54,550 I'm sure you did great. 13 00:00:54,550 --> 00:00:55,896 Let's take another look at our JSON. 14 00:01:02,707 --> 00:01:06,632 We now have all the data we need to create a new CurrentWeather object using 15 00:01:06,632 --> 00:01:08,162 our CurrentWeather model. 16 00:01:12,781 --> 00:01:17,130 There are several data points to fill in here, so let's get started. 17 00:01:17,130 --> 00:01:17,750 Go back over here to MainActivity. 18 00:01:20,956 --> 00:01:22,880 Let's create our CurrentWeather object. 19 00:01:24,020 --> 00:01:25,390 CurrentWeather. 20 00:01:25,390 --> 00:01:26,250 Call it currentWeather. 21 00:01:27,490 --> 00:01:27,990 New CurrentWeather object. 22 00:01:31,060 --> 00:01:33,255 Now we set all the values from our data model. 23 00:01:38,190 --> 00:01:38,690 SetHumidity. 24 00:01:42,750 --> 00:01:44,271 It's a double, so we getDouble. 25 00:01:48,424 --> 00:01:52,227 And it's humidity. 26 00:01:56,021 --> 00:01:57,860 SetTime. 27 00:02:03,090 --> 00:02:04,597 GetLong, and that's time. 28 00:02:11,730 --> 00:02:12,230 Set our Icon. 29 00:02:22,045 --> 00:02:26,737 For the location label, we'll just hard code the location, Alcatraz Island, 30 00:02:26,737 --> 00:02:27,570 California. 31 00:02:29,173 --> 00:02:34,250 CurrentWeather, SetLocationLabel, 32 00:02:38,500 --> 00:02:45,861 Alcatraz Island, California. 33 00:02:48,360 --> 00:02:49,477 Oops. 34 00:02:51,968 --> 00:02:57,941 CurrentWeather.setPrecipChance. 35 00:03:00,476 --> 00:03:07,765 And that's a double, and that key was precipProbability. 36 00:03:15,836 --> 00:03:16,980 Set the Summary. 37 00:03:20,299 --> 00:03:24,096 GetString("summary"). 38 00:03:24,096 --> 00:03:31,130 And then we'll set the Temperature. 39 00:03:37,407 --> 00:03:40,670 And that's a double, and that's temperature. 40 00:03:43,892 --> 00:03:45,965 Now that we have a CurrentWeather object, 41 00:03:45,965 --> 00:03:48,220 we can return that instead of returning null. 42 00:03:52,653 --> 00:03:55,750 Great work! 43 00:03:55,750 --> 00:03:58,700 How do we check that everything is working so far, though? 44 00:03:58,700 --> 00:04:01,800 We don't have a layout yet to view all this data. 45 00:04:01,800 --> 00:04:06,880 We could add a lot of log statements to our code, but that seems tedious. 46 00:04:06,880 --> 00:04:08,550 Let's use the debugger. 47 00:04:08,550 --> 00:04:10,590 If we set a break point in our code, 48 00:04:10,590 --> 00:04:13,420 we can investigate the variables at that break point. 49 00:04:13,420 --> 00:04:15,285 So let's set a break point here at CurrentWeather. 50 00:04:16,910 --> 00:04:18,237 And run the app, using the debugger. 51 00:04:24,510 --> 00:04:32,200 Go here into the Debug screen Show our currently object, 52 00:04:36,050 --> 00:04:44,560 Step into it, So right now, we don't have any values anywhere. 53 00:04:44,560 --> 00:04:45,286 We step over each line. 54 00:04:48,421 --> 00:04:51,940 If we open up CurrentWeather, we notice we don't have any values. 55 00:04:53,250 --> 00:04:59,413 If we step over, Everything will get populated line by line. 56 00:05:08,394 --> 00:05:10,170 Congratulations! 57 00:05:10,170 --> 00:05:13,130 We now have a fully populated data model. 58 00:05:13,130 --> 00:05:13,640 Nice work.