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

Popular posts from this blog

C# random value from dictionary and tuple -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -