1

向 json-parser 提供以下数据:http ://mapadosradares.com.br/api/get_initial_load会产生此错误:在最外层数组或对象之后不需要令牌“数组开始”

这是我的代码:

- (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];
}
4

1 回答 1

2

您是否在请求之间正确初始化解析器?您尚未显示您的代码,但如果您通过解析器对提要运行两次连续调用,这似乎是一个合理的错误。

顺便说一句,我通过http://jsonlint.com上出色的 JSON 解析器运行了提要输出,它看起来确实不错。

于 2012-02-10T01:38:01.743 回答