Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Weather App with Swift (Retired) Pulling Data From the Web JavaScript Object Notation

Updated way to print JSON

Clicking the white button on forecastURL wasn't showing me anything other than the forecastURL object, no data.

When I converted the data to a String, the JSON printed out:

let string1 = NSString(data: weatherData!, encoding: NSUTF8StringEncoding)
println(string1!)

4 Answers

Add the code you're working with so we can better answer your question.

The white button didn't show anything to me when I click it as well, instead the following statement

<p>let forecastURL = NSURL(string: "22.2341,-110.2223145", relativeToURL: baseURL)"</p>

<p>Some https://api.forecast.io/forecast/apiKey/22.2341,-110.2223145</p>

But if you hover your mouse next to the link and click on the eye-looking button, another window pops out with all the JSON data

Joshua Peterson
Joshua Peterson
17,515 Points

This should sort out the problem!

let apiKey = "INSERT_YOUR_API_KEY"


let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")
let forecastURL = NSURL(string: "37.8267,-122.423", relativeToURL: baseURL)
forecastURL!
CHRISTOPHER RUNCO
CHRISTOPHER RUNCO
2,165 Points

I couldn't get any of these to work so I just copied the whole url and pasted it into a safari address bar and up comes all the JSON data.

https://api.forecast.io/forecast/yourapicodegoeshere/yourlongandlatgoeshere/