1

Actually in getting JSON data from a sql server in a encypted format and i decrypt the json data and stored in a NSString. So i have to copy the stored json string to a NSDictionary. So that i can able to call each and every data using valueForKeys.

NSString *requestMode = @"Hello buddy";
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://funsip.com/interaction_demo.php?requestMode=LIBRARY&categoryid=3"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[requestMode dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSError *err = nil;
NSHTTPURLResponse* response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err ];
if (err != nil) { NSLog(@"Failed"); }

NSString* answernew = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding]; `

so i want to copy the ansernew string to a NSDictionary.

Thanks in advance K.Karthik

taskinoor
  • 45,586
  • 12
  • 116
  • 142
karthik
  • 11
  • 3

2 Answers2

3

If you are targetting iOS 5.0, you can use NSJSONSerialization to parse the data:

NSError *error;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

You don't have to convert data to a string first.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
0

You'll need JSONkit for that.

Kyr Dunenkoff
  • 8,090
  • 3
  • 23
  • 21