Iphone 当本地服务器返回json格式的空数据(json对象)时,应用程序崩溃?
这是我调用Web服务的代码。Iphone 当本地服务器返回json格式的空数据(json对象)时,应用程序崩溃?,iphone,xcode,json,localserver,Iphone,Xcode,Json,Localserver,这是我调用Web服务的代码。 (无效)viewDidLoad { [超级视图下载] //Make this controller the delegate for the location manager.self.mapview.delegate = self; [self.mapview setShowsUserLocation:YES]; //Instantiate a location object. locationManager = [[CLLocationManager al
(无效)viewDidLoad
{
[超级视图下载]
//Make this controller the delegate for the location manager.self.mapview.delegate = self;
[self.mapview setShowsUserLocation:YES];
//Instantiate a location object.
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
//Set some parameters for the location object.
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
firstLaunch=YES;
NSURL*url=[NSString stringWithFormat:@”http://198.71.54.13/service.php?CategoryID=%@&子类别id=%@&纬度=%@&经度=%@&半径=100000type=list“,_cat_id,_subcat_id,currentcenter.latitude,currentcenter.longitude,app_var.radius];
NSURL *googleRequestURL=[NSURL URLWithString:url];
// Retrieve the results of the URL.
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
// NSValue* data12 = [NSValue dataWithContentsOfURL: googleRequestURL];
NSLog(@"%@ data",data);
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
-(void)fetchedData:(NSData *)responseData
{
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSArray* places = [json objectForKey:@"business"];
[self plotPositions:places];
}
**OUTPUTS**
响应数据
-[\uu NSArrayI objectForKey:]:发送到实例0x910e490的无法识别的选择器
2012-10-19 15:17:56.242 SESpringBoardDemo[1731:13a03]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[\uu NSArrayI objectForKey::]:未识别的选择器发送到实例0x910e490'
responseData
尝试加载项-(void)fetchedData:(NSData*)responseData此代码行:
NSLog(@"responseData: %@", responseData);
并在此处写入responseData结果字符串。使用尝试加载项-(void)fetchedData:(NSData*)responseData时,NSDictionary和NSArray中似乎出现错误。此代码行:
NSLog(@"responseData: %@", responseData);
然后在这里写一个responseData结果字符串。在NSDictionary和NSArray中使用崩溃中的可以清楚地看到这个错误
reason: '-[__NSArrayI objectForKey:]'
您正试图在NSArray上启动objectForKey
方法。您将其视为字典,但它似乎是我的数组
如果仍然无法解决您的问题。请将responseData转换为字符串并检查实际响应,它肯定会对您有所帮助。从崩溃中您可以清楚地看到
reason: '-[__NSArrayI objectForKey:]'
您正试图在NSArray上启动objectForKey
方法。您将其视为字典,但它似乎是我的数组
如果仍然无法解决您的问题。请将responseData转换为字符串并检查实际响应,这肯定会对您有所帮助。感谢您的回复。我会尝试并让您知道。感谢您的回复。我会尝试并让您知道。