-1

尽管我们有很多人问过同样的问题,但没有一个答案有助于解决我的问题。所以这是我的代码,

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSString *text = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
    NSLog(@"Response: %@", text);



    //The NSJSONSerialization method to transform the NSData responseObject into a dictionnary does work
    NSJSONSerialization *jsonResponse = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];

    //This NSLog makes the app crash with an unrecognized selector sent error
    NSLog(@"JSON: %@",jsonResponse);

    NSArray *result1=(NSArray *)[jsonResponse valueForKeyPath:@"result"];

    NSLog(@"result1: %@",result1);

    NSMutableString  *shipPrice =[[NSMutableString alloc]init];
    NSMutableString  *freeLimitString =[[NSMutableString alloc]init];

    if(result1!=Nil && ![result1 count]==0)
    {
               for (int i=0; i<result1.count; i++)
               {
                    NSNumber *totalShippingPrice = [[result1  objectAtIndex:i] valueForKeyPath:@"totalShippingPrice"];
                    if( totalShippingPrice != nil && totalShippingPrice && [totalShippingPrice isEqualToNumber:0]&& [totalShippingPrice intValue]==0) // ISSUE LINE
                                {
                                    shipPrice = (NSMutableString*)@"FREE";
                                } } } } 

我保留了断点,并且它确实发生在上面的这一行中。我是新手AFNetworking。我不知道如何解决它。帮助我提供工作代码示例:) 谢谢

4

1 回答 1

6

你需要使用这个:

[totalShippingPrice isEqualToNumber: [NSNumber numberWithInt:0]]

在崩溃的行中。您需要将该对象与另一个相同类型的对象进行比较,如果您使用 0 与您向其发送 nil 相同,因此您需要按照我写的那样创建一个 NSNumber 。

或者只是这样做:

[totalShippingPrice intValue] == 0
于 2013-07-08T14:08:18.860 回答