- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 RKObjectMapping 执行对象映射。
这是我的 JSON 示例:
{
"notification": {
"created_at": "2012-10-23T02:43:43-04:00",
"delivered": true,
"id": 3915,
"missed": false,
"rejected": false,
"search_request_id": 360,
"bid": {
"bid_type": "none",
"bid_type_values": null,
"comment": "hi\n",
"created_at": "2012-10-23T02:43:54-04:00",
"delivered": true,
"delivery_type": "email",
"id": 268,
"has_chat_session": true,
},
"search_request": {
"created_at": "2012-10-23T02:43:42-04:00",
"customer_id": 6,
"id": 360,
"latitude": "40.7536854",
"location": "10001",
"longitude": "-73.9991637",
}
}
我已经使用 jsonlint 验证了 JSON,它是有效的。
这是我的映射。
RKObjectMapping *bidMapping = [RKObjectMapping mappingForClass:[Bid class]];
[bidMapping mapKeyPath:@"comment" toAttribute:@"comment"];
[bidMapping mapKeyPath:@"chat_session_id" toAttribute:@"chatSessionId"];
[objectManager.mappingProvider setMapping:bidMapping forKeyPath:@"bid"];
RKObjectMapping *searchRequestMapping = [RKObjectMapping mappingForClass:[SearchRequest class]];
[searchRequestMapping mapKeyPath:@"purpose" toAttribute:@"purpose"];
[searchRequestMapping mapKeyPath:@"customer_Id" toAttribute:@"customerId"];
[searchRequestMapping mapKeyPath:@"need" toAttribute:@"need"];
[objectManager.mappingProvider setMapping:searchRequestMapping forKeyPath:@"search_request"];
RKObjectMapping *notificationMapping = [RKObjectMapping mappingForClass:[Notification class]]; // have not mapped all the attributes.
[notificationMapping mapKeyPath:@"id" toAttribute: @"notificationId"];
[notificationMapping mapKeyPath:@"created_at" toAttribute:@"timestamp"];
[notificationMapping mapKeyPath:@"vendor_id" toAttribute:@"vendorId"];
[notificationMapping mapKeyPath:@"bid" toRelationship:@"bid" withMapping:bidMapping];
[notificationMapping mapKeyPath:@"search_request" toRelationship:@"search_request" withMapping:notificationMapping];
[objectManager.mappingProvider setMapping:notificationMapping forKeyPath:@"notification"];
程序因断言失败而崩溃,当我尝试加载ObjectsAtResourcePath时,我无法调试该失败。我也尝试使用 rootKeyPaths 但没有成功。
有人可以帮我找出错误吗?
谢谢!
ps:我想添加一个 NSDictionary 参数,文档说使用appendQueryParams:params。但我收到一条警告,说它已被弃用。我可以使用任何替代方案吗?
最佳答案
您在这里给出了错误的映射-
[notificationMapping mapKeyPath:@"search_request" toRelationship:@"search_request" withMapping:notificationMapping];
你应该给 searchRequestMapping 像 -
[notificationMapping mapKeyPath:@"search_request" toRelationship:@"search_request" withMapping:searchRequestMapping];
您可以使用 RKClient 的方法以下方法来代替appendQueryParams:params-
- (RKRequest *)get:(NSString *)resourcePath queryParameters:(NSDictionary *)queryParameters delegate:(NSObject<RKRequestDelegate> *)delegate;
关于iphone - 使用 RKObjectMapping 进行嵌套映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13265152/
我没有回应: { "orders": [ { "date": "2013-11-18T13:00:39.000Z", "state": "new", "
请帮助使用 RestKit 进行集合映射,我不知道如何做到这一点。 我的 JSON 就像 { "result":{ "success":"1", "message":"You logg
我是 RestKit 的新手,正在尝试映射一个 json 对象,其中包含我的模型的对象数组。我已经调试并发现响应命中我的服务器-> json 返回-> RestKit 说映射成功并且我映射了 1 个对
我正在使用 RestKit iOS 包来允许用户从他们拥有的帐户中提取信息。下面的代码在第一次通过时完美运行。但是,如果我第二次尝试使用不同的用户名和密码,它只会加载第一次映射调用中的信息。此外,当第
我正在尝试使用 RKObjectMapping 执行对象映射。 这是我的 JSON 示例: { "notification": { "created_at":
所以,我有一个 api 调用,它将以下面的格式输出一些原始 json... 有点乱,但我只对此 json 的 Mapping 部分感兴趣。如果我能够访问原始数据,我会将 json 序列化为我想要迭代的
我正在使用 RestKit 的对象映射将 JSON 数据映射到对象。 是否可以将纬度和经度 JSON 属性映射到 CLLocation我的 Objective-C 类中的变量? JSON: { "it
假设我有这样的 JSON: { "hits": 4056, "books": [ { "name": "Book 1" },
我有一个名为 Activity 的 swift 模型,它可以选择附加一个 coordinate。 import MapKit class Activity: NSObject { var co
我“pod update”,现在我的RestKit版本是0.25.0,我的RKValueTransformers是1.1.2,出现错误“RKObjectMapping.h”not found。 Res
我想在嵌套的 RLMObject 中设置相同的主键。 如何使用 RKObjectMapping 设置相同的 id? 首先,我制作了以下 json 文件。 JSON 文件 { "id": 1 "
如何使用 RestKit RKObjectMapping 映射下面嵌套的 json?我只需要映射“数据”。我当前的下面代码返回 (null) - 谢谢! { "sucess": true,
我有以下代码: NSString *url = @"http://mysite.com" RKURL *baseURL = [RKURL URLWithBaseURLString:url];
我想更新我的一些项目 pod,在运行 pod update "some_framework"并尝试构建项目后出现此错误: import "RKObjectMapping.h" file not fou
我正在尝试使用 RestKit 0.24.0 将 JSON NSString 映射到一个对象,其中我有一个 RKObjectMapping 以及相应的字典。 网上的大部分解决方案都是引用RestKit
我是一名优秀的程序员,十分优秀!