Question

Hi all so after a lot of hassle I managed to finally work my way around achieving and delimiting the JSON returned by Twitter Streaming APIs. How do i store the data returned by [NSJSONSerialization JSONObjectWithData:options:error:] into an array in appending mode???

Here are the codes To call the Streaming API

self.twitterConnection = [[NSURLConnection alloc] initWithRequest:signedReq delegate:self startImmediately: NO];

and in the delegate method (which is did receive data method)

NSError *parseError = nil; self.dataSource=[NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments|NSJSONReadingMutableContainers error:&parseError]; What i want to do is to store this NSJSONSerialized output in a static Array(preferably in append mode) so that i can pass it to table view for display. how do i go about it?

Thanks in Advance

EDIT

`self.dataSource1=[[NSMutableArray alloc]init];

NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

string = [NSString stringWithFormat:@"[%@]", [string

stringByReplacingOccurrencesOfString:@"\r\n" withString:@","]]; NSError *parseError = nil; self.dataSource =[NSJSONSerialization JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments|NSJSONReadingMutableContainers error:&parseError];

[self.dataSource1 addObjectsFromArray:self.dataSource];`

Was it helpful?

Solution

Use -[NSMutableArray addObjectsFromArray:] to add objects to a mutable array.

Based on your comment, it looks like you're recreating self.dataSource1 every time you get data in didReceiveData. You should only create the object once before sending the request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top