NSDictionary objectForKey返回错误的值

Dam*_*ski 0 json key object nsdictionary ios

我正在尝试使用我从服务器获得的JSON响应字典.当我打印字典的描述时,一切都井然有序

    Printing description of dict:
{
    category = 1;
    code = 1;
    name = "xxxx";
    pictureUrl = "xxxx";
    sessionId = xxx;
    status = 0;
}
Run Code Online (Sandbox Code Playgroud)

我需要"代码"值,当我使用objectForKey:@"code"来获取它时,我得到一个错误的值:

int code = [NSDictionary objectForKey:@"code"];
Run Code Online (Sandbox Code Playgroud)

在此之后我打印出代码的值和它的东西,如3483765348,这是非常非常错误的.

为什么会这样?

tok*_*kou 7

返回的对象是NSNumber而不是int(不是对象).如果你想要int值,试试这个

int code = [[myDictionary objectForKey:@"code"] intValue];
Run Code Online (Sandbox Code Playgroud)