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」]; –
編譯器不會終止您的應用程序。它只是編譯。 (附註) –