开发者

How to Extract a Enum value from an NSDictionary in iOS obtained by parsing a JSON response

I have a .net JSON web service which returns a json string when queried. I obtain that JSON string and parse it into a NSDictionary using SBJSON Parser. Now my .net web service adds an enum value to the response which when parsed into NSdictionary looks like this

"Name":0,

I need to extract this value on iOS client side. Any ideas how do I go about it.

I tried doing following things

int *val = [[dictionary objectForKey:@"Name"] intValue];
开发者_开发问答

I know this is not the right way of doing this. I guess i need to store the result in an NSNumber object, But how do i extract an NSNumber value from NSDictionary.

Any help would be appreciated.

Thanks


What you are doing is valid. The intermediate object you are pulling out and sending the intValue message is an NSNumber created by the json parser. If you want an NSNumber, just do this instead:

    NSNumber *name = [dictionary objectForKey:@"Name"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜