为什么要终止? [英] Why it is terminating?

查看:159
本文介绍了为什么要终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

responseData = [[NSMutableData data] retain];
 NSString *requestString = [NSString stringWithFormat:@"http://api.yelp.com/business_review_search?term=&lat=%f&long=%f&radius=10&limit=20&ywsid=XXXXXXXXXX&category=%@",[[ListofLat objectAtIndex:i] floatValue], [[ListofLong objectAtIndex:i] floatValue],appDelegate.categoryField] ; 
//NSURL *url = [[NSURL alloc] initWithString:requestString];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:requestString]];
/*  NSData *tempData =[[NSData alloc] initWithContentsOfURL:url];
    NSString *Str = [[NSString alloc] initWithData:tempData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",Str);*/
NSURLResponse *response = nil;
NSError *error = nil;
//getting the data
NSData *newData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//json parse
NSString *responseString = [[NSString alloc] initWithData:newData encoding:NSUTF8StringEncoding];
NSDictionary *jsonObject = [responseString JSONValue];
//Accessing JSON content
NSLog(@"message :  %@", [jsonObject objectForKey:@"message"] );
    NSArray *status = [jsonObject objectForKey:@"message"] ;
    NSLog(@"message :  %@", status );
            for(NSDictionary *response in status)
                    {
                        NSString *Resptxt =[response objectForKey:@"text"];
                        txtStatus=[Resptxt copy];
                    }

    if([txtStatus isEqualToString : @"OK"])
    {
        UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message: @"The request completed without error. " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [info show];
        [info release];
    }

我正在使用上面的代码进行json解析.当编译器出现在这一行上

I am using above code for json parsing. when compiler comes on this line

NSString * Resptxt = [响应objectForKey:@"text"];

NSString *Resptxt =[response objectForKey:@"text"];

然后编译器终止并给出此错误

then compiler terminate and give this error

* 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[[NSCFString objectForKey:]:无法识别的选择器已发送到实例0x6166490'

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x6166490'

状态为

'消息':{'代码':0,'文本':'确定','版本':'1.1.0'}}

'message': {'code': 0, 'text': 'OK', 'version': '1.1.0'}}

这是什么问题?我该如何纠正?

What is problem in this? How i correct it?

推荐答案

这看起来并不像编译器遇到的错误.而是在运行应用程序时遇到的错误.

This doesn't look like an error the compiler encounters. Rather it's an error you run into when running your app.

它表示您已向消息objectForKey:发送到字符串实例,即响应是一个字符串实例.但是,此消息通常发送到NSDictionary的实例.

It indicates that you sent to message objectForKey: to a string instance, i.e. response is a string instance. However, this message is normally sent to instance of NSDictionary.

我假设JSON响应的结构与您期望的不同.特别是,它比您的代码所假设的嵌套得更深.

I assume that the JSON response has a different structure than you expect. In particular, it is more deeply nested than your code assumes.

请发布完整的JSON答案,以便我们为您提供更具体的帮助.

Please post the full JSON answer so we can give you more specific help.

这篇关于为什么要终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆