我对新的 restkit 10.0 中的 RKObjectMapping 感到困惑。我已经用 RKClient 调用了我的 web 服务,并以 JSON 的形式得到了响应。现在我想用我的 User 类映射 JSON 字符串。怎么做 ?
{"id":2,"displayName":"Giri Bhushan","roles":null,"username":"FBUser-123456","password":"dddddddddddddddd=\r\n","email":"test@gmail.com","gender":"M","birthDate":null,"friends":null,"bloodGroup":null,"firstName":null,"lastName":null,"phoneNumber":null}
我试过下面的代码:
RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping mapKeyPath:@"id" toAttribute:@"userId"];
[userMapping mapKeyPath:@"displayName" toAttribute:@"displayName"];
[userMapping mapKeyPath:@"userName" toAttribute:@"userName"];
[userMapping mapKeyPath:@"password" toAttribute:@"password"];
[userMapping mapKeyPath:@"email" toAttribute:@"email"];
[userMapping mapKeyPath:@"gender" toAttribute:@"gender"];
[userMapping mapKeyPath:@"birthDate" toAttribute:@"birthDate"];
[userMapping mapKeyPath:@"bloodGroup" toAttribute:@"bloodGroup"];
[userMapping mapKeyPath:@"firstName" toAttribute:@"firstName"];
[userMapping mapKeyPath:@"lastName" toAttribute:@"lastName"];
[userMapping mapKeyPath:@"phoneNumber" toAttribute:@"phoneNumber"];
[[RKObjectManager sharedManager].mappingProvider setMapping:userMapping forKeyPath:@"user"];
但是,如何使用 RKObjectMapping 映射 JSON 字符串?