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
jon kelson
5,149 Pointsplease help how do i manipulate this piece of JSON code
// HI I've written this bit of code in Xcode and want to set up some code so i can tap on a button and a different value comes out in a label from the JSON file. (ps I've downloaded Alamofire and SwiftJSON . )
how would i go about doing that in Swift?
Alamofire.request(.GET, "http://").responseJSON { (response) -> Void in //check if the response has a value if let value = response.result.value { let json = JSON(value)
print("This is (CEO) \(json[0]) ")
3 Answers
Moritz Lang
25,909 PointsYou could use arc4_random and pass in the count of items in your JSON as upper bound.
jon kelson
5,149 PointsThank you Moritz,
this is the 1st time ive used JSON etc before . ive been asked to extact and display diferent parts of the JSON file so.. It was the real basic beginning of the code I needed to get my head around, to be able to get any of the code from the code i've written and just display it in a a label or button in my xcode project.
your probably a lot more advanced than me, as I cant even begin to start to know how to do that. what ive written so far and what ive wanted to display in a label is this ....
print("This is Marks Mason (CEO) (json[0]) ") // this displays Marks details in the debug area. // but I wanted to display it in a label
Moritz Lang
25,909 PointsJon, you shouldn't start iOS-Development by learning such specific tasks. Just follow some of these awesome beginner courses here on Treehouse and you soon will understand.
jon kelson
5,149 Pointsok thanks Moritz , I've got through to the intermediat in swift coarse after around a year of learning with treehouse so maybe by doing this project I'm jumping a bit to far on.
I just thought there may be a simple bit of code to go with what I've already written as above just to pull out the arrays and display them on the view instead of the debug area ,
I know the basics in swift but possibly not the basics to go with the JSON that I'm using in my Xcode project.
maybe ill put the project on the back burner until I do the Swift Networking coarse.