Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 当本地服务器返回json格式的空数据(json对象)时,应用程序崩溃?_Iphone_Xcode_Json_Localserver - Fatal编程技术网

Iphone 当本地服务器返回json格式的空数据(json对象)时,应用程序崩溃?

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

这是我调用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 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];


    });

}
  • 这里我正在获取Json数据

    -(void)fetchedData:(NSData *)responseData 
     {
        NSError* error;
    NSDictionary* json = [NSJSONSerialization 
                                  JSONObjectWithData:responseData                               
                                  options:kNilOptions 
                                  error:&error];
    
     NSArray* places = [json objectForKey:@"business"]; 
    [self plotPositions:places];
    }
    
    
                                             **OUTPUTS**
    
  • 当没有来自json的数据时,我在控制台中收到以下错误:

    响应数据
    -[\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转换为字符串并检查实际响应,这肯定会对您有所帮助。

    感谢您的回复。我会尝试并让您知道。感谢您的回复。我会尝试并让您知道。