-1

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];`

holierthanthou84
  • 227
  • 2
  • 12
  • I don't understand. Do you mean `-[NSMutableArray addObjectsFromArray:]`? – maroux May 02 '13 at 15:04
  • Thanks for the prompt reply MarOux!! I did try your suggestion but it seems only the last fetched data is being added to the mutable array. I've tried a lot of things. But nothing is really working out for me. the problem with streamed api is the data is returned dynamically. If i keep displaying the data as it comes usually only one row in table view is displayed. maybe im missing out how to call function and deal with data. Btw have you ever worked with twitter (or rather any) Streaming APIs?? – holierthanthou84 May 03 '13 at 04:53
  • add the code where you call `addObjectsFromArray:` (or other `NSMutableArray` methods) – maroux May 03 '13 at 04:55
  • where data is the data returned by Streaming APIs in the above edit :) – holierthanthou84 May 03 '13 at 05:05

1 Answers1

0

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.

maroux
  • 3,764
  • 3
  • 23
  • 32