2012-02-10 1 views
1

このデータを使用してjson-parserにフィード:http://mapadosradares.com.br/api/get_initial_loadこのエラーは、トークン 'start of array'私は、JSONは完全に罰金です言うことができる限りjson-framework - 最も外側の配列またはオブジェクトの後でトークン '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"); 
    } 
} 

:または

はここに私のコードであるオブジェクト。何かご意見は?

UPDATE:

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

答えて

2

あなたが適切に要求間のパーサを初期化されています

ここでパーサーinitalizationですか?あなたのコードは表示されていませんが、パーサーを通じた2回の連続した呼び出しを実行した場合には、これが妥当なエラーであるようです。

ところで、フィード出力を優れたJSONパーサー(http://jsonlint.com)で実行したところ、問題はないようです。

+0

パーサの初期化で質問を更新しました。もう1つの要求は別のパーサーによって処理されます。彼らは国家を共有することはできますか? – Raphael

+0

このオブジェクトはデリゲートのNSURLConnectionを初期化して起動する唯一の場所ですか?接続開始時にログステートメントを変更してみてください。didReceiveData:接続オブジェクトのアドレスを表示します。パーサーに複数の接続がある場合は、おそらくそれが問題です。 –

+0

私はそれを試してみますが、データが正しく印刷されているため、それが原因だとは思われません。 – Raphael

関連する問題