JSON Serialization in Swift iOS -


how can serialize json in swift? trying serialize using method, causing exc_bad_instruction. downloading json data, using nsurlconnection.

var sjson : nsdictionary = nsjsonserialization.jsonobjectwithdata(nsmutdata, options: nsjsonreadingoptions.mutablecontainers, error: nil) nsdictionary 

how can solve it?

regards

your root-level data array of dictionaries -- not dictionary; therefore replace line with:

var sjson = nsjsonserialization.jsonobjectwithdata(nsmutdata, options: .mutablecontainers, error: nil) nsarray 

i tested , works data.

here's how tested after having created "json.txt" file in project:

var filepath  = nsbundle.mainbundle().pathforresource("json", oftype:"txt") var nsmutdata = nsdata(contentsoffile:filepath) var sjson     = nsjsonserialization.jsonobjectwithdata(nsmutdata, options: .mutablecontainers, error: nil) nsarray 

Comments