没有根Json元素的响应描述符

时间:2016-03-09 04:13:21

标签: ios json restkit

{
    "id": 76,
    "name": "Tom Timberley",
    "gender": 1,
    "follower_count": 1,
    "following_count": 1,
    "me_following": [{
        "id": 5,
        "status": "ACCEPTED",
        "following_me": {
            "id": 2,
            "status": "ACCEPTED"
        }
    }]
}

没有外部Json对象。当我following_me时,有什么办法可以从对象RKRelationshipMapping访问根对象吗?

我有表Following_meUser,我想将用户数据Json的根映射到Following_me

[following_me_mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"@root" toKeyPath:@"user" withMapping:userMapping]];

此处following_me_mappingFollowing_me表的映射,userMappingUser表的映射。

但指定@root无效。

[RKResponseDescriptor responseDescriptorWithMapping:mapping
                                             method:RKRequestMethodGET
                                        pathPattern:nil
                                            keyPath:nil
                                    statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)
 ];

这是我添加响应描述符的方式。

3 个答案:

答案 0 :(得分:0)

也许你可以使用“MJExtension.Framework”来表示“json to model”数据(https://github.com/CoderMJLee/MJExtension),将这些数据显示在模型而不是json数据(字典)上可以简化你的问题,祝福!〜 〜

答案 1 :(得分:0)

@media print {

     body * {
    visibility: hidden;!important;
  }

  #gmap {
    position: absolute; !important;
    left: 0;
    top: 0;
  }
}

答案 2 :(得分:0)

您似乎在向后思考问题,并对您的响应描述符处理的内容感到困惑。

通过设置pathPattern:nil keyPath:nil,您的响应描述符将对您所做的任何请求都有效(它不会被路径模式过滤)并且将从根处理JSON有效负载(没有关键路径导航到)。

因此,您的初始映射已经应该处理根。然后,您为me_following键添加关系以处理该内容。在该映射中,您可以为following_me添加关系。

通过这种方式,您可以向下钻取数据映射,而不是您想要深入研究的描述,然后尝试再次导航(这需要一种相当不同且更复杂的方法)。