ios - Trying to access information from a nsdictionary created by json -
i trying access information in nsdictionary created json , can't seem figure out how access values. i've gotten dictionary print out can't access specific keys/values: here json
[ { "id": "1", "question": "how old you", "answers": [ "7", "9", "13" ] }, { "id": "2", "question": "how old you", "answers": [ "7", "9", "13" ] } ]
my biggest confusion format when log out dictionary:
nslog(@"%@", questionsandanswers);
i back:
( { answers = ( 7, 9, 13 ); id = 1; question = "how old you"; }, { answers = ( 7, 9, 13 ); id = 2; question = "how old you"; } )
so display order different input order suppose isn't big deal. want like:
nsarray *answersarray = [questionsandanswers allkeysforobject:@"answers"];
which kind of learned here :http://rypress.com/tutorials/objective-c/data-types/nsdictionary.html
but errors no matter how i've been formatting it.
here code dictionary:
nsstring *filepath = [[nsbundle mainbundle] pathforresource:@"datajson" oftype:@"json"]; nsdata *jsondata = [nsdata datawithcontentsoffile:filepath options:nsdatareadingmappedifsafe error:nil]; questionsandanswers = [nsjsonserialization jsonobjectwithdata:jsondata options:nsjsonreadingmutablecontainers error:nil];
any on subject appreciated! keep in mind novice ios developer.. researched few hours no avail
questionsandanswers
array of dictionaries. can access id of first question by: questionsandanswers[0]["id"]
the id of second question questionsandanswers[1][@"id"]
, on.
Comments
Post a Comment