菜鸟教程小白 发表于 2022-12-12 14:32:39

ios - RestKit:如何处理以不同 JSON 有效负载交付子项的情况?


                                            <p><p>我正在尝试连接到一个 API,该 API 仅嵌入子 ID,而不是对象本身。
例如:</p>

<pre><code>{
&#34;post&#34;: {
      &#34;id&#34;: 1,
      &#34;title&#34;: &#34;New post&#34;,
      &#34;body&#34;: &#34;A body!&#34;,
      &#34;comment_ids&#34;: [ 1, 2, 3 ]
}
}
</code></pre>

<p>要获取<code>post.comments</code>,需要再次查询API。</p>

<p>我查看了这个 RestKit 的单元测试来创建连接:
<a href="https://github.com/RestKit/RestKit/blob/development/Tests/Logic/ObjectMapping/RKObjectManagerTest.m#L1453-L1484" rel="noreferrer noopener nofollow">https://github.com/RestKit/RestKit/blob/development/Tests/Logic/ObjectMapping/RKObjectManagerTest.m#L1453-L1484</a> </p>

<p>我认为它正在工作。但是有一点我不明白:</p>

<p>如果代码中的某处我需要访问注释:</p>

<pre><code>pots.comments.anyObject
</code></pre>

<p>我必须手动触发 http get,还是 RestKit 会自动延迟加载?看起来需要手动完成,但我不知道该怎么做。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>RestKit 不会自动延迟加载。您通常会在需要发布详细信息时触发下载(例如在主从设置中显示详细 View 时)。</p>

<p>您可能需要一个请求描述符,以便在您发布帖子时 RestKit 将发送评论 ID。那么响应将是一个帖子对象(或至少是一个容器)和一个评论列表。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - RestKit:如何处理以不同 JSON 有效负载交付子项的情况?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18770065/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18770065/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - RestKit:如何处理以不同 JSON 有效负载交付子项的情况?