我正在从URL解析JSON数据。 URL有数据,但数组在代码中返回null这里是我用于解析的代码。
tempArray =[[DataController staticVersion] startParsing:[NSString stringWithFormat:@"http://ec2-54-84-162-129.compute-1.amazonaws.com/hotelcms/getActivityHotel.php?ActivityDate=Sunday March 15th&ActivityNameID=1"]];
NSLog(@"Temp Array is %@",tempArray);
这是DataController类
@interface DataController : NSObject {
}
+ (id)staticVersion;
- (NSMutableArray *) startParsing:(NSString *)theURLString;
@end
@implementation DataController
DataController *theInstance;
+ (id)staticVersion
{
if(!theInstance){
theInstance = [[DataController alloc] init];
}
return theInstance;
}
- (NSMutableArray *) startParsing:(NSString *)theURLString {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",theURLString]];
NSString *fileContent= [NSString stringWithContentsOfURL:url];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *data = (NSDictionary *) [parser objectWithString:fileContent error:nil];
NSArray *items = (NSArray *) data ;
return items;
}
@end
答案 0 :(得分:1)
该URL的响应不是有效的JSON对象。看看你是否可以删除错误的" 3月15日周日"从回应开始。