ios - How to parse JSON when there is no key but only an Integer / String value? -
how can parse this json file ? code working when both keys , values available .
my code far :
let url = url(string: "http://uhunt.felix-halim.net/api/uname2uid/felix_halim") let task = urlsession.shared.datatask(with: url!, completionhandler: { (data, response, error) in print("task started") if error != nil { print("in error!") } else { if let content = data { { let myjson = try jsonserialization.jsonobject(with: content, options: .mutablecontainers) anyobject print(myjson) } catch { print("in catch!") } } } }) task.resume() print("finished")
if root object of json not dictionary or array have pass .allowfragments option (btw. never pass .mutablecontainers, it's meaningless in swift)
let url = url(string: "http://uhunt.felix-halim.net/api/uname2uid/felix_halim")! let task = urlsession.shared.datatask(with: url) { data, response, error in print("task started") guard error == nil else { print("in error!", error!) return } { if let myjson = try jsonserialization.jsonobject(with: data!, options: .allowfragments) as? int { print(myjson) } } catch { print("in catch!", error) } } task.resume() print("finished")
Comments
Post a Comment