ios - How to get an integer value from NSDictionary? -


i having weird issue. nsdictionary not returning correct integer value.

json response code server.

{ "status":"ok", "error_code":0, "data" : [], "msg":"everything working!" } 

the json being converted nsdictionary.

nserror *error = nil; nsdictionary *jsondict = [nsjsonserialization                           jsonobjectwithdata:data                           options:nsjsonreadingmutablecontainers                           error: &error]; 

i access nsdictionary value using following code.

int error_code = (int)[jsondict valueforkey:@"error_code"] nslog(@"%i", error_code); log outputs following: 143005344 

i've tried objectforkey , same response.

thanks, in advance.

yes outputs pointer of value , that's why see log output.

you cannot cast pointer integer , expect value.

int error_code = [[jsondict valueforkey:@"error_code"] integervalue]; 

or if want use modern objective-c

int error_code = [jsondict[@"error_code"] integervalue]; 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -