2012-02-10 96 views
1

使用此數據提供json解析器:http://mapadosradares.com.br/api/get_initial_load會產生此錯誤:令牌「數組的起始位置」或對象json-framework - 在最外面的數組或對象之後不會出現令牌'數組的開始'

這裏是我的代碼:

- (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是完全正常的。有什麼想法嗎?

UPDATE:

這裏的解析器initalization:

- (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

你正確初始化請求之間的解析器?你還沒有顯示你的代碼,但是如果你通過解析器連續兩次調用feed,這似乎是一個合理的錯誤。

順便說一句,我運行通過優秀的JSON解析器在http://jsonlint.com的飼料輸出,它似乎沒有問題。

+0

我用解析器初始化更新了我的問題。另一個請求由另一個解析器處理。他們可以分享國家嗎? – Raphael 2012-02-10 01:41:37

+0

這是你初始化並觸發其委託爲此對象的NSURLConnection的唯一地方嗎?嘗試修改連接開始時的日誌語句:didReceiveData:打印連接對象的地址;如果您看到多個連接與解析器對話,那可能是問題所在。 – 2012-02-10 01:47:57

+0

我會嘗試,但我不認爲這是數據正確打印的原因。 – Raphael 2012-02-10 01:49:08