Thursday, 15 August 2013

ios - Data conversion from JSON results as NSDictionary[] throws EXC_BAD_INSTRUCTION runtime error -



ios - Data conversion from JSON results as NSDictionary[] throws EXC_BAD_INSTRUCTION runtime error -

i have next json beingness received in swift code, after beingness parsed nsdictionary. in function trying extract json objects in "results" block nsdictionary[], throwing run-time error. don't understand why, working few days earlier.

{ "results": [ { "id": "3", "name": "the national", "slug": "thenational", "facebook_url": "https://www.facebook.com/thenationalofficial/", "twitter_url": "https://twitter.com/the_national", "profile_image": "http://example.staging.com/media/profile_image/thumbnail_263x263/1352756032.jpg", "_type": "artist", "resource_uris": { } }, { "id": "5", "name": "mayer hawthorne", "slug": "mayerhawthorne", "facebook_url": "https://www.facebook.com/mayerhawthorne", "twitter_url": "https://twitter.com/mayerhawthorne", "profile_image": "http://example.example.com/media/profile_image/thumbnail_263x263/1352755133.png", "_type": "artist", "resource_uris": { } }, { "id": "20", "name": "i play maracas", "slug": "iplaymaracas", "facebook_url": "", "twitter_url": "", "profile_image": "http://staging.wedemand.com/images/en/img-list-home.gif", "_type": "artist", "resource_uris": { "_demanded_by": null, "demand_url": "http://ec2-54-86-17-163.compute-1.amazonaws.com/artists/20/?demand=1&access_token={}", "dismiss_url": "http://ec2-54-86-17-163.compute-1.amazonaws.com/artists/20/?demand=0&access_token={}" } }, { "id": "35", "name": "black superheros", "slug": "blacksuperheros", "facebook_url": "", "twitter_url": "", "profile_image": "http://staging.example.com/images/en/img-list-home.gif", "_type": "artist", "resource_uris": { } }, { "id": "49", "name": "ayman elgadi", "slug": "aymanelgadi", "facebook_url": "", "twitter_url": "", "profile_image": "http://staging.example.com/images/en/img-list-home.gif", "_type": "artist", "resource_uris": { } }, { "id": "8874", "name": "lauri", "slug": "lauri", "facebook_url": "http://www.facebook.com/hughlaurieblues", "twitter_url": "http://twitter.com/hughlaurieblues", "profile_image": "http://staging.example.com/media/profile_image/thumbnail_263x263/lauri_profilepic.jpg", "_type": "artist", "resource_uris": { } } ] }

my ios-swift code receives nsdictionary object after beingness parsed afnetworking lib , passes function casts results array nsdictionary[], throwing run-time error, while before working.

(operation: afhttprequestoperation!, responseobject: anyobject!) in println("json: " + responseobject.description) var jsonresult: nsdictionary = responseobject nsdictionary

this jsonresult passed function below tries cast nsdictionary[]

let allresults: nsdictionary[] = results["results"] nsdictionary[]

update: printed class of results object beingness returned __nscfdictionary.

here what nscfdictionary? give-and-take regarding , says utilize nsdictionary, in case not working.

the value of results not dictionary in json, array. should this;

let allresults: nsarray = results["results"] nsarray

ios json swift

No comments:

Post a Comment