Parsing string json in swift 3 -


i have json saved in string format , i´m trying use:

let json = "{'result':[{'name':'bob','age':'27'}]}"; 

using jsonserialization comes error cannot invoke jsonoject argument...

if let json = try jsonserialization.jsonobject(with: json) as? [string: any],    let array = json["result"] as? [[string: any]] {    item in array {        if let name = item["name"] as? string {           if name == "bob" {              self.age = int((item["age"] as? string)!)!           }        }     } } 

i tryed use this solution no success.

please @ declaration of jsonobject(with) ⌥-click on symbol.

the first parameter of type data have convert string data.

a major issue json not formatted correctly. string indicators must double quotes.

let json = "{\"result\":[{\"name\":\"bob\",\"age\":27}]}" let jsondata = json.data(using: .utf8) {     if let result = try jsonserialization.jsonobject(with: jsondata!) as? [string: any],    ...    self.age = item["age"] as! int 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -