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."]}}
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."]}}
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];
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
.