我想用SBJSon库解析那些在iOS上具有类似结构的Json
谁能帮我?非常感谢!

{“错误”:{“用户名”:[“用户名已被使用。”],“电子邮件”:[“电子邮件已被使用。”]}}

最佳答案

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);


//输出

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


使用SBJSon

SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [str JSONValue];

关于ios - SBJson在iOS上解析数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18265925/

10-12 00:14
查看更多