Skip to main content

JSON String to Object and vice-varsa


Object To JSON String: 

NSArray *values = [[NSArray alloc] initWithObjects : @"1", @"Test123", nil];
NSArray *keys = [[NSArray alloc] initWithObjects : @"id", @"name", nil];
NSDictionary *dict = [[NSDictionary alloc] initWithObjects : values forKeys : keys];
NSError *err;
NSData *data = [ NSJSONSerialization dataWithJSONObject : dict options:0 error :&err ];
    NSString *jsonString = [[NSString alloc] initWithData : data encoding : NSUTF8StringEncoding];


JSON String To Object:

//jsonString is the string that we want to parsed 

NSDictionary *responseDic = [NSJSONSerialization JSONObjectWithData:jsonString options:nil error:&error];






Comments