So in the last lesson, we manage to figure out how to use Alamofire to make a HTTP GET request and grab 1
a whole bunch of information from Wikipedia. 2
Now, in this lesson, we're going to pass that information and display it inside our app in a label, like 3
so. 4
So we've done this before in both Clima and FlashChat, so I want to set it as a challenge and see if 5
you can turn this response into a JSON, and then parse that JSON in order to grab the relevant extract, and 6
put it into a label. 7
It might involve a little bit of design work as well. 8
Here's a hint 9
before you start working on the challenge. When we printed this response in the last lesson, the data 10
type of that response is a DataResponse object. 11
Now, that is not same as a JSON, and you want to be able to use something like Jason editor online to 12
be able to visualize the JSON structure more easily. 13
So in order to turn it into a JSON, remember, we need to use the SwiftyJSON framework. So we can write 14
JSON, 15
and then we can convert that response.result.value into a JSON value. 16
So let me show you side by side the differences. If you have a look over here, 17
this is our Data Response Object, and on the right is the same thing that's been converted into a JSON. 18
You can see that in the JSON structure, all the keys are Strings, and they have quotation marks around 19
them, whereas in the object, the keys are simply as they are. 20
Now, if you tried to put this Data Response Object into the JSON editor straight away, you can see 21
that it's going to give you a whole bunch of errors, and it won't be able to parse it because this is 22
not JSON. But after you've converted it, then it will be able to parse it without any problems. 23
And the idea is that you want to use this structure to guide your JSON parsing. 24
So if you don't remember how we parsed JSON using SwiftyJSON, then have a look back at CLIMA or at 25
FlashChat and remind yourself how he managed to chain keys together in order to get to the thing that 26
we want which is, of course, this extract over here. 27
So I'm going to set this as a challenge, give it a go, and see if you can do it. 28
Don't worry if you can't, I'm going to walk you through the solution in the next lesson.