Reputation: 814
i would ask a little help..
I have a function which try to get json data from a url. I am using SwiftyJSON.
this is my function:
func getDataFromUpc(Code: String) {
print("called getdata")
let urlString = "http://api.upcdatabase.org/json/mykey/" + Code
print(urlString)
let url = NSURL(string: urlString)
let data = NSData(contentsOfURL: url!)
let json = JSON(data!)
print(json)
print(json["description"])
self.alert(json["description"].stringValue)
}
when i try to print the json object on the console i can see this: unknown
and when i try to print json["description"] it's nil.
If i try to call my url with my browser it's works and i get back the json response.
Could anybody please help me what am I doing wrong?
Thank you very much!
Upvotes: 0
Views: 1024
Reputation: 601
swiftyJSON don´t works with URL´s , swiftJSON works perfectly with local data
this is a tutorial that you can see to understand more the swiftJSON
https://www.youtube.com/watch?v=_NfijT6mt6A
to parse the JSON from the web you need to do that...
https://www.youtube.com/watch?v=r-LZs0De7_U
Upvotes: 1