Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to parse json data from a string instead of a URL
    primarykey
    data
    text
    <p>I want to parse a json data which is in NSString how can i do this </p> <pre><code> NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(@"%@",data); NSArray *tempArray =[[DataController staticVersion] startParsing:data]; for (int i = 0; i&lt;[tempArray count]; i++) { id *item = [tempArray objectAtIndex:i]; NSDictionary *dict = (NSDictionary *) item; SearchCode *theObject =[[SearchCode alloc] init]; [theObject setCodeValue:[dict objectForKey:@"CodeValue"]]; [theObject setCodeDescription:[dict objectForKey:@"CodeAddedDate"]]; [theObject setCodeAddedDate:[dict objectForKey:@"CodeAddedDate"]]; [theObject setCodeID:[dict objectForKey:@"CodeID"]]; [theObject setUpdateDateTime:[dict objectForKey:@"UpdateDateTime"]]; [cptArray addObject:theObject]; [theObject release]; theObject=nil; } </code></pre> <p>DataController Class</p> <pre><code>@interface DataController : NSObject { } + (id)staticVersion; - (NSMutableArray *) startParsing:(NSString *)theURLString; @end #import "DataController.h" #import "JSON.h" @implementation DataController DataController *theInstance; +(id)staticVersion { if(!theInstance){ theInstance = [[DataController alloc] init]; } return theInstance; } - (NSMutableArray *) startParsing:(NSString *)theURLString { NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",theURLString]]; NSString *fileContent= [NSString stringWithContentsOfURL:url]; SBJSON *parser = [[SBJSON alloc] init]; NSDictionary *data = (NSDictionary *) [parser objectWithString:fileContent error:nil]; NSArray *items = (NSArray *) data ; return items; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload