0

I want to parse those Json that has a structure like this on iOS, with SBJSon libs Can anyone help me? thanks so much!

{"error":{"username":["The username has already been taken."],"email":["The email has already been taken."]}}

Leon Yuu
  • 11
  • 1
  • 3
    Your question not clear dude . Is that bolded words are the response you are getting or what? – Tendulkar Aug 16 '13 at 04:45
  • You can use SBJson Library for parsing JSON structures in iOS.. Heres the link http://stackoverflow.com/a/5813223/1042240 – Ahmed Z. Aug 16 '13 at 04:54

2 Answers2

2
NSString *str=@"{\"error\":{\"username\":[\"The username has already been taken.\"],\"email\":[\"The email has already been taken.\"]}}";

NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];

NSDictionary *json = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: nil];

NSLog(@"dic is %@",json);

//output

dic is {
    error =     {
        email =         (
            "The email has already been taken."
        );
        username =         (
            "The username has already been taken."
        );
    };
}

Using SBJSon

SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [str JSONValue];
Prince Kumar Sharma
  • 12,591
  • 4
  • 59
  • 90
0
SBJsonParser * parser = [[SBJsonParser alloc] init];
NSObject * responseobj = [parser objectWithData:data]; // for NSData
NSObject * responseobj = [parser objectWithString:string]; // for NSString

In your case "responseobj" will be of type NSDictionary.

Vishal Kardode
  • 961
  • 2
  • 8
  • 25