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解析。当编译器出现在这行为什么它终止?
NSString * Resptxt = [response objectForKey:@“text”];
然后编译终止,给这个错误
*终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因是: ' - [NSCFString objectForKey:]:无法识别的选择发送到实例0x6166490'
包含的状态是
'message':{'code':0,'text':'OK','version':'1.1.0'}}
这是什么问题?我如何改正它?
你可以在这里粘贴包含状态... – Robin
试试这个NSString * Resptxt = [response valueForKey:@“text”]; –
编译器不会终止您的应用程序。它只是编译。 (附注) –