我目前正在尝试使用他们的流 API 从 Twitter 流式传输数据。我附上了下面的代码,用于创建我的NSData
并将其附加到didReceiveData
. 出于某种原因,每次didReceiveData
从 Twitter 收到响应时,它都会作为新的 JSON 根附加NSData
到NSData
.
我无法弄清楚发生了什么并将 JSON 发布到验证器中,它注意到 JSON 中有多个根。如何修改代码以继续附加到现有的 JSON 根?或者当 ? 中有多个 JSON 条目时,是否有更简单的方法来反序列化为 JSON NSData
?
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// A response has been received, this is where we initialize the instance var you created
// so that we can append data to it in the didReceiveData method
// Furthermore, this method is called each time there is a redirect so reinitializing it
// also serves to clear it
NSLog(@"Did receive response");
_responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// Append the new data to the instance variable you declared
NSLog(@"Did Receive data");
[_responseData appendData:data];
}