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];
}
我用解析器初始化更新了我的問題。另一個請求由另一個解析器處理。他們可以分享國家嗎? – Raphael 2012-02-10 01:41:37
這是你初始化並觸發其委託爲此對象的NSURLConnection的唯一地方嗎?嘗試修改連接開始時的日誌語句:didReceiveData:打印連接對象的地址;如果您看到多個連接與解析器對話,那可能是問題所在。 – 2012-02-10 01:47:57
我會嘗試,但我不認爲這是數據正確打印的原因。 – Raphael 2012-02-10 01:49:08