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

リクエスト間でパーサーを適切に初期化していますか?コードを表示していませんが、パーサーを介してフィードに対して2回連続して呼び出しを実行した場合、これは予想どおりのエラーのようです。

ちなみに、http://jsonlint.comにある優れたJSONパーサーを介してフィード出力を実行しましたが、問題ないようです。

于 2012-02-10T01:38:01.743 に答える