- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试运行一些单元测试来测试我与 RestKit v0.20 的映射,但是我收到一个错误消息,指出我的目标对象为 nil。我已经追踪到映射失败的事实,因为 sourceType 是一个 NSArray 而我的 destinationType 是一个 NSNumber。我认为这是因为我的映射键路径不正确。我正在尝试将 songCard JSON 映射到我的对象。我在下面包含了我的 JSON 和映射测试。如果有人可以帮助我设置正确的键路径,那就太好了。
{"status" : 2000,
"content" : {
"cardList" : [
{
"songCard" : {
"likes" : 2,
"dislikes" : 3
}
}
]
},
"message" : "OK"
}
单元测试类
- (RKObjectMapping *)songMetadataMapping
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[SongMetadata class]];
[mapping addAttributeMappingsFromDictionary:@{
@"content.cardList.songCard.likes": @"likes"
}];
return mapping;
}
- (void)testSongMetadataMapping
{
NSString *parsedJSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"songMetadata.json"];
RKMappingTest *test = [RKMappingTest testForMapping:[self songMetadataMapping] sourceObject:parsedJSON destinationObject:nil];
[test addExpectation:[RKPropertyMappingTestExpectation expectationWithSourceKeyPath:@"content.cardList.songCard.likes" destinationKeyPath:@"likes" value:@"2"]];
STAssertTrue([test evaluate], @"Mappings failed");
}
更新进一步调试后,我发现我的 JSON 字符串中的值 2 被评估为 NSArray,而这应该被评估为 NSNumber。作为快速测试,我删除了我的 JSON 中的 [ ] 并且值 2 被正确评估为 NSNumber。这并不能解决我的问题,因为我需要将我的 JSON 标识为一组 songCard 对象
最佳答案
正如您所注意到的,您不能使用您在播放数组时指定的键路径。我可以想到两个选项 - 第一个是远景,但关键路径 content.cardList[0].songCard.likes
是否有效?
否则,考虑使用方法:
+ (instancetype)expectationWithSourceKeyPath:(NSString *)sourceKeyPath
destinationKeyPath:(NSString *)destinationKeyPath
evaluationBlock:(RKMappingTestExpectationEvaluationBlock)evaluationBlock;
使用 keypath content.cardList
并提供评估 block 1) 检查映射是否是包含单个对象的数组。然后,您可以检查该对象是否包含一个 songCard
对象,并且该对象的 likes
值为 2。
关于ios - Reskit - 映射到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14275631/
我正在尝试运行一些单元测试来测试我与 RestKit v0.20 的映射,但是我收到一个错误消息,指出我的目标对象为 nil。我已经追踪到映射失败的事实,因为 sourceType 是一个 NSArr
我只是想问一下,是否有办法解析Reskit中的以下字段“mods”: post_count: false, sitename: "Mercury", mods: false, admin_email:
经过长时间的研究,我正在写这篇文章,但我真的很难找到解决我问题的最佳方法。 我对 resKit 和 CoreData 都很陌生......无论如何,我正在映射并保存我从 Web 服务接收到的 JSON
先是结构,再是解释 •[J] (json 根) ••[A] (A 对象数组) •••[A1] (A1的数据) •••[A2] (A2的数据) •••[A3] ( ... ) •••• [A3.B] (
嗨 stackoverflow 社区,我正在使用 RKObjectManager 发出 iOS RESTful 请求以将响应映射到本地对象。 我对 Restkit 的问题是在不同的请求中为同一个元素注
提取后数据库中出现重复项。 下面是映射和获取代码: +(RKEntityMapping *)userMapping:(RKEntityMapping *)userMapping { [user
我正在后台线程中执行 getObjectsAtPath。但是,成功/失败 block 是在 UI 线程上调用的。 有没有办法强制 RestKit 在同一个线程而不是 UI 线程上调用成功和失败 blo
我正在尝试映射 RSS 提要的项目。 RKObjectRequestOperation 返回对象的确切数量,但属性值为 nil。以下是我的代码 NSURL *requestURL = [NSURL
在我的应用程序中,我进行了不同的调用,除了一个调用外,它们都有效,该调用仅返回一个字符串作为响应作为 SUCCESS。我收到这个错误 "The operation couldn’t be comple
我正在尝试用 key 包装我的 HTTP POST 请求。换句话说,我想把这个: { "category_id"=>"1", "food_name_token"=>"Pizza", "id"=>"1
我正在尝试将 RestKit 与 Django-Tastypie 创建的 REST API 绑定(bind)。GET 操作运行良好,但 POST 操作有奇怪的行为:在数据库中创建了一行,但所有字段都是
{ "JobID" : "aaaabbbb-dddd-eeee-ffff-aaaabbbbcccc", "UserID": "11112222-dddd-eeee-ffff-111122223333"
我很困惑要遵循什么 REST API 才能与 RestKit 同步。我在发出放置/发布/删除请求时遇到问题。 我遵循的 REST API 之一来自 NetTuts我发现很难与 RestKit 同步。
我有以下代码: NSString *url = @"http://mysite.com" RKURL *baseURL = [RKURL URLWithBaseURLString:url];
我将如何使用 Restkit 上传音频文件?我查看了文档,似乎找不到有关上传文件的任何信息。感谢您的帮助。 最佳答案 本文解释了如何:http://mobile.tutsplus.com/tutori
我有一个现有的 Core Data 应用程序,我现在想为其添加 REST 支持以远程存储我的对象。我决定集成 RestKit,因为它似乎(到目前为止)是最成熟的 REST 支持框架,但我对它的核心数据
我完全按照 RestKit 设置说明进行操作,但我在带库的链接二进制文件中得到的 libRestKit.a 是红色的。 安装说明: https://github.com/RestKit/RestKit
我是一名优秀的程序员,十分优秀!