ios - Parser to json JSON array using swift -



ios - Parser to json JSON array using swift -

i doing ios (swift) app communicates server. response server json array contains json objects. when show console string response fine:

[{"name":"","surname":"","id":5,"username":"dpcabo2"},{"name":"","surname":"","id":10,"username":"default"},{"name":"","surname":"","id":11,"username":"esteban"}]

but when seek parser info json using this:

var jsonresult: nsdictionary = nsjsonserialization.jsonobjectwithdata(self.my_data!, options:nsjsonreadingoptions.mutablecontainers, error: nil) nsdictionary println("\(jsonresult)")

app crashes.

so need solution parser correctly information.

ps.self.my_data! nsmutabledata.

thanks

you can utilize below code parsing. prints , parse object properly.

import foundation allow jsonobject: [anyobject] = [ ["name":"","surname":"","id":5,"username":"dpcabo2"], ["name":"","surname":"","id":10,"username":"default"], ["name":"","surname":"","id":11,"username":"esteban"] ] allow jsonoptional: anyobject! = nsjsonserialization.jsonobjectwithdata(jsondata, options: nsjsonreadingoptions(0), error: nil)

response below:

[["username": "dpcabo2", "id": 5, "name": "", "surname": ""], ["username": "default", "id": 10, "name": "", "surname": ""], ["username": "esteban", "id": 11, "name": "", "surname": ""]]

ios json swift

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -