Fem*_*ina -1 objective-c ios afnetworking
虽然我们有很多人问同样的问题,但没有一个答案有助于解决我的问题.所以这是我的代码,
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";
} } } }
Run Code Online (Sandbox Code Playgroud)
我保留了断点,正好在上面这行中发生了.我是新来的AFNetworking.我不知道如何解决它.帮我处理代码示例:)谢谢
你需要使用这个:
[totalShippingPrice isEqualToNumber: [NSNumber numberWithInt:0]]
Run Code Online (Sandbox Code Playgroud)
在线崩溃.你需要将对象与另一个相同类型的对象进行比较,如果你使用0就像你发送nil一样,所以你需要在我写的时候创建一个NSNumber.
或者只是做:
[totalShippingPrice intValue] == 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3806 次 |
| 最近记录: |