Ios 在设备上调试应用程序时,REST API调用未获取数据

Ios 在设备上调试应用程序时,REST API调用未获取数据,ios,objective-c,ipad,xcode5,Ios,Objective C,Ipad,Xcode5,我通过以下方式在我的应用程序中调用RESTAPI -(NSArray*)parse_Data_From_URL:(NSString*)URL { NSURL *myURL = [[NSURL alloc]initWithString:URL]; // we'll receive raw data so we'll create an NSData Object with it NSData *myData = [[NSData alloc]initWithConten

我通过以下方式在我的应用程序中调用RESTAPI

-(NSArray*)parse_Data_From_URL:(NSString*)URL
{

    NSURL *myURL = [[NSURL alloc]initWithString:URL];

    // we'll receive raw data so we'll create an NSData Object with it
    NSData *myData = [[NSData alloc]initWithContentsOfURL:myURL];

    // now we'll parse our data using NSJSONSerialization
    id myJSON = [NSJSONSerialization JSONObjectWithData:myData options:NSJSONReadingMutableContainers error:nil];


    // typecast an array and list its contents

    NSArray *jsonArray = [NSArray new];
    jsonArray = (NSArray *)myJSON;

  //  NSLog(@"json floor plan imageTite --- %@",jsonArray);

    return jsonArray;

}

当我在iPad模拟器上运行我的应用程序时,我的代码工作正常,但当我在设备上运行应用程序时,它API响应获取空值&应用程序将终止。

你不应该忽视可能出现错误的事实:

-(NSArray*)parse_Data_From_URL:(NSString*)URL
{

    NSURL *myURL = [[NSURL alloc]initWithString:URL];

    // we'll receive raw data so we'll create an NSData Object with it
    NSData *myData = [[NSData alloc]initWithContentsOfURL:myURL];

    // now we'll parse our data using NSJSONSerialization
    NSError *err = nil;
    NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:myData options:NSJSONReadingMutableContainers error:&err];

    if (err) {
        // do something about error
        NSLog("Error retrieving data: %@", err);
    }

    // this will be nil if there is an error.  May want to consider adding NSError ** to parse_Data_From_URL parameters
    return jsonArray;

}

1)
NSArray*jsonArray=[NSArray新]
是不必要的,因为您在它之后立即将
myJSON
分配给它。2) 将
myJSON
类型转换为
NSArray
不会自动将对象转换为数组(例如,您可能会得到一个字典)。3) 只需在反序列化后设置断点,并检查对象和任何错误。是否确认您的设备具有internet连接?是否我的设备具有internet连接。