Exploring the Data4:27 with Ken Alger
Dark Sky is sending us data in JSON format. What exactly are we working with? Let's take a look!
[MUSIC] 0:00 Stormy has taught us a great deal thus far. 0:01 We've learned about asynchronous requests, and how to make them over the network, 0:07 in parallel with the main UI thread. 0:12 We're connecting to the Dark Sky servers, and getting usable weather data back. 0:14 Thus far, I've clouded over the data format of JSON a few times in this course. 0:19 Guess what? 0:24 Now's the time to explore this data format. 0:25 We need to look at the actual data that Dark Sky is sending our app and 0:29 see how it can be displayed on the screen. 0:33 Recall from our previous project the design 0:36 pattern called Model View Controller or MVC. 0:39 This is a great opportunity for us to cover these principles again. 0:42 We'll take a look at the view in an upcoming stage, so 0:46 let's not worry about that just yet. 0:49 To begin then, let's create some model objects to store the data from 0:52 Dark Sky that we want to display. 0:57 I've put a couple of links to videos as resources 0:59 if you'd like to review the MVC pattern further. 1:02 Briefly, the idea is this. 1:06 The Model View Controller, MVC design pattern allows us to separate parts of our 1:07 software into components that allow for reuse, and better organization. 1:12 I find that ordering at a restaurant is a good example. 1:17 You have a waiter who controls what is being ordered. 1:20 A chef in the background uses the data and objects of the recipe, the model, 1:24 to make the order. 1:29 And the food itself, is what is viewed. 1:30 The chef can only model objects that she has access to, tortillas, 1:33 rice, beans, salsa, etc. 1:38 The waiter controls what food can be ordered. 1:41 If it isn't on the menu, they control that. 1:44 Finally you as the customer, gets to view the arrangement of the data objects. 1:47 Clearly in Android apps, we don't have chefs and 1:52 waiters running around inside our devices. 1:55 Android apps implement the MVC pattern with the View being the layout on 1:58 the screen that the user sees. 2:03 The controller is the activity that presents views or responds to user input. 2:05 the activity also interacts with the data model. 2:11 And that data model is typically a set of classes that represent our data. 2:13 Let's take a look at the Dark Sky developer's page and the response format. 2:19 This provides some good detail about the different data points being returned. 2:24 What's also helpful is to see the raw data that Stormy gets. 2:29 We go back to our developers console page. 2:32 Here we see a sample API call we can make with the coordinates 2:36 of the Alcatraz Island, California. 2:39 We click on this link, we are provided with a raw JSON data. 2:41 Nice but not super helpful. 2:46 As right now it is somewhat challenging to read. 2:48 JSON data can be formatted in a very readable fashion. 2:51 There are a few ways to do so. 2:55 You can copy and paste this into an online JSON formatter or 2:57 you can install a browser extension. 3:00 I'm using the Chrome browser but 3:03 adding extensions to other browsers should be fairly similar. 3:04 If we look at the Chrome Web Store. 3:08 Let's search for JSON here. 3:15 There are many choices here. 3:20 I personally like this JSON Viewer one. 3:22 We'll add it. 3:28 Now if we refresh our page, much easier to read. 3:34 We can now easily expand and contract sections and explore the data. 3:40 For our Stormy app we're really only interested in this currently section here. 3:47 This particular section the JSON data has all the information we'll need for 3:53 our app. 3:57 We'll look at this more closely in a moment. 3:58 But let's look at our mock ups and think about our data as it relates to our view. 4:00 In looking at the markup, 4:04 we see that we're going to be recording our location and icon, a brief summary, 4:06 along with the time, temperature, humidity, and chance of precipitation. 4:10 This should be enough to keep us from feeling washed away with tasks for 4:15 this version of Stormy. 4:19 We'll use this markup as our guide when we come back and 4:20 create some Java objects in the model portion of our MVC pattern 4:23
You need to sign up for Treehouse in order to download course files.Sign up