Ios NSDictionary被视为boolean-can';t调试 NSDictionary*tokenData=[[responseDict objectForKey:@“data”]objectForKey:@“multipass”]; dispatch\u async(dispatch\u get\u main\u queue()^{ NSString*card=[NSString stringWithFormat:@“%@-%@”, [[UserAccount sharedInstance]卡号], [tokenData objectForKey:@“CardPhoneToken”]];/

Ios NSDictionary被视为boolean-can';t调试 NSDictionary*tokenData=[[responseDict objectForKey:@“data”]objectForKey:@“multipass”]; dispatch\u async(dispatch\u get\u main\u queue()^{ NSString*card=[NSString stringWithFormat:@“%@-%@”, [[UserAccount sharedInstance]卡号], [tokenData objectForKey:@“CardPhoneToken”]];/,ios,objective-c,xcode,debugging,Ios,Objective C,Xcode,Debugging,在解析前,我会检查tokenData是否是NSDictionary NSDictionary *tokenData = [[responseDict objectForKey:@"data"] objectForKey:@"multipass"]; dispatch_async(dispatch_get_main_queue(), ^{ NSString *card = [NSString stringWithFormat:@"%@-%@", [[UserAccount

在解析前,我会检查
tokenData
是否是
NSDictionary

NSDictionary *tokenData = [[responseDict objectForKey:@"data"] objectForKey:@"multipass"];
dispatch_async(dispatch_get_main_queue(), ^{
    NSString *card = [NSString stringWithFormat:@"%@-%@",
        [[UserAccount sharedInstance] cardNumber],
        [tokenData objectForKey:@"CardPhoneToken"]]; //<-- problem
});
-(无效)加载数据
{
NSDictionary*tokenData=[[responseDict objectForKey:@“数据”]objectForKey:@“多路径”];
dispatch\u async(dispatch\u get\u main\u queue()^{
NSString*cardPhoneToken=@;
if([tokenData IsKindof类:[NSDictionary类]]){
retryCount=0;
cardPhoneToken=[tokenData objectForKey:@“cardPhoneToken”];
}否则{
NSLog(@“加载数据失败,正在重试…”);
retryCount++;
如果(retryCount<5){
[自动加载数据];
回来
}否则{
NSLog(@“重试5次后失败”);
}
}
NSString*card=[NSString stringWithFormat:@“%@-%@”,
[[UserAccount sharedInstance]卡号],
cardPhoneToken];
});
}

在解析前,我会检查
tokenData
是否是
NSDictionary

NSDictionary *tokenData = [[responseDict objectForKey:@"data"] objectForKey:@"multipass"];
dispatch_async(dispatch_get_main_queue(), ^{
    NSString *card = [NSString stringWithFormat:@"%@-%@",
        [[UserAccount sharedInstance] cardNumber],
        [tokenData objectForKey:@"CardPhoneToken"]]; //<-- problem
});
-(无效)加载数据
{
NSDictionary*tokenData=[[responseDict objectForKey:@“数据”]objectForKey:@“多路径”];
dispatch\u async(dispatch\u get\u main\u queue()^{
NSString*cardPhoneToken=@;
if([tokenData IsKindof类:[NSDictionary类]]){
retryCount=0;
cardPhoneToken=[tokenData objectForKey:@“cardPhoneToken”];
}否则{
NSLog(@“加载数据失败,正在重试…”);
retryCount++;
如果(retryCount<5){
[自动加载数据];
回来
}否则{
NSLog(@“重试5次后失败”);
}
}
NSString*card=[NSString stringWithFormat:@“%@-%@”,
[[UserAccount sharedInstance]卡号],
cardPhoneToken];
});
}
听起来很熟悉。:)

将块更改为:

-(void)loadData
{
    NSDictionary *tokenData = [[responseDict objectForKey:@"data"] objectForKey:@"multipass"];
    dispatch_async(dispatch_get_main_queue(), ^{
        NSString *cardPhoneToken = @"";
        if( [tokenData isKindOfClass:[NSDictionary class]] ){
            retryCount = 0;
            cardPhoneToken = [tokenData objectForKey:@"CardPhoneToken"];
        } else {
            NSLog(@"failed to load data, retrying...");
            retryCount++;
            if( retryCount < 5 ){
                [self loadData];
                return;
            } else {
                NSLog(@"failed after 5 retries");
            }

        }
        NSString *card = [NSString stringWithFormat:@"%@-%@",
                          [[UserAccount sharedInstance] cardNumber],
                          cardPhoneToken];

    });
}
^{
NSString*卡;
if([tokenData是Kindof类[NSDictionary类]){
card=[NSString stringWithFormat:@“%@-%@”,
[[UserAccount sharedInstance]卡号],
[tokenData objectForKey:@“CardPhoneToken”];//听起来很熟悉。:)

将块更改为:

-(void)loadData
{
    NSDictionary *tokenData = [[responseDict objectForKey:@"data"] objectForKey:@"multipass"];
    dispatch_async(dispatch_get_main_queue(), ^{
        NSString *cardPhoneToken = @"";
        if( [tokenData isKindOfClass:[NSDictionary class]] ){
            retryCount = 0;
            cardPhoneToken = [tokenData objectForKey:@"CardPhoneToken"];
        } else {
            NSLog(@"failed to load data, retrying...");
            retryCount++;
            if( retryCount < 5 ){
                [self loadData];
                return;
            } else {
                NSLog(@"failed after 5 retries");
            }

        }
        NSString *card = [NSString stringWithFormat:@"%@-%@",
                          [[UserAccount sharedInstance] cardNumber],
                          cardPhoneToken];

    });
}
^{
NSString*卡;
if([tokenData是Kindof类[NSDictionary类]){
card=[NSString stringWithFormat:@“%@-%@”,
[[UserAccount sharedInstance]卡号],

[tokenData objectForKey:@“CardPhoneToken”]];//您可以输入json,或者将响应记录在
多路径
对象的字典中吗?似乎您正在从
数据
字典中拉出一个
NSNumber
。这就是它崩溃之前的样子:
{code=200;data={multipass=0;};};}
您能不能请psot这个json,或者您能不能请NSLog这个响应,它是
multipass
对象还是一个字典?看起来您正在从
数据
字典中拉出一个
NSNumber
。这就是它崩溃之前的样子:
{code=200;data={multipass=0;};}
当我发现
tokenData
不是
NSDictionary
时,您可以在我的更新问题中看到,我需要处理它。我的问题是,如何“重新加载”
tokenData
以获取
NSDictionary
?我应该调用
NSDictionary*tokenData=[[responsedit objectForKey:@“data”]objectForKey:@“multipass”];
再次?可能在
while
中,以确保它是
NSDictionary
?当我尝试这样做时:
while(![tokenData有点像类:[NSDictionary类]){tokenData=[[responsedit objectForKey:@“data”]objectForKey:@“multipass”];}
我得到一个错误
变量不可赋值(缺少块类型说明符)
因为没有关联数组(=dictionary),所以无法重新加载它在您的JSON输入中。您将以某种方式将其视为异常。您可以通过指定一个字典来“伪造”字典。但我想这可能没有多大帮助。这是您的第二条评论。您建议的while循环肯定会永远运行。除非,可能,NSDictionary的内容在另一个线程中更改。B但这仍然不是一种聪明的设计。正如你在我更新的问题中看到的,当我发现
tokenData
不是
NSDictionary
时,我需要处理它。我的问题是,如何“重新加载”
tokenData
以获得
NSDictionary
?我应该调用
NSDictionary*tokenData=[[responsedit objectForKey:@“data”]objectForKey:@“multipass”];
再次?可能在
while
中,以确保它是
NSDictionary
?当我尝试这样做时:
while(![tokenData有点像类:[NSDictionary类]){tokenData=[[responsedit objectForKey:@“data”]objectForKey:@“multipass”];}
我得到一个错误
变量不可赋值(缺少块类型说明符)
因为没有关联数组(=dictionary),所以无法重新加载它在您的JSON输入中。您将以某种方式将其视为异常。您可以通过指定一个字典来“伪造”字典。但我想这可能不会有多大帮助。这是您的第二条评论。您建议的while循环肯定会永远运行。除非,可能,NSDictionary的内容通过