向json解析器提供this data:http://mapadosradares.com.br/api/get_initial_load会产生以下错误:标记'start of array‘不应出现在最外层的数组或对象之后
下面是我的代码:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"Connection didReceiveData of length: %u", data.length);
// Printing the received data
size_t length = [data length];
unsigned char aBuffer[length];
[data getBytes:aBuffer length:length];
//aBuffer[length - 1] = 0;
NSLog(@"\n\n\n\n%s\n\n\n\n", aBuffer);
SBJsonStreamParserStatus status = [parser parse:data];
if (status == SBJsonStreamParserError) {
NSLog(@"Parser error: %@", parser.error);
} else if (status == SBJsonStreamParserWaitingForData) {
NSLog(@"Parser waiting for more data");
}
}据我所知,JSON是完全正常的。有什么想法吗?
更新:
下面是解析器的初始化:
- (void) getInitialLoad
{
adapter = [[SBJsonStreamParserAdapter alloc] init];
parser = [[SBJsonStreamParser alloc] init];
adapter.delegate = self;
parser.delegate = adapter;
NSString *url = @"http://mapadosradares.com.br/api/get_initial_load";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}发布于 2012-02-10 09:38:02
您是否正确地初始化了请求之间的解析器?您还没有展示您的代码,但是如果您通过解析器连续两次调用提要,那么这似乎是一个合理的错误。
顺便说一句,我通过http://jsonlint.com上优秀的JSON解析器运行了提要输出,它看起来确实很好。
https://stackoverflow.com/questions/9221543
复制相似问题