Home  >  Q&A  >  body text

objective-c - iOS怎样通过这样的JSON数据,实现上下拉刷新加载更多

{
"count": 87,
"next": "http://127.0.0.1:5000/api/v1.0/posts/?page=2",
"posts": [
{
"author": "http://127.0.0.1:5000/api/v1.0/users/2",
"body": "\u66f4\u597d\u6591\u6591\u9a73\u9a73\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d",
"body_html": null,
"body_title": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/1/comments/",
"id": 1,
"timestamp": "Wed, 24 Jun 2015 06:40:03 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/1"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/2",
"body": "\u770b\u770b\u770b\u770b\u5361\u5361\u5361\u5361\u9760\u9760\u9760\u9760\u9760\u9760\u9760",
"body_html": null,
"body_title": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/2/comments/",
"id": 2,
"timestamp": "Wed, 24 Jun 2015 06:40:31 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/2"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/2",
"body": "uuuuuuuuuuuuuuuuuuu\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684",
"body_html": null,
"body_title": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/3/comments/",
"id": 3,
"timestamp": "Wed, 24 Jun 2015 06:40:44 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/3"
}
],
"prev": null
}

请问怎样通过这样的JSON数据,实现下拉刷新加载更多,是要判断id吗?还是创建时间?或者输出怎样的JSON数据更方便一些?

ringa_leeringa_lee2676 days ago492

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 15:03:51

    数据

    next字段可以不需要,客户端可以通过count字段计算出下一次请求的页码。
    count字段只需要在获取第一页数据时返回。

    逻辑要点

    • 下拉刷新:清空本地所有数据,加载第一页。
    • 上拉加载:使用当前页码加载数据。
    • 下拉刷新上拉加载加载网络数据成功后的共同逻辑:加载成功后通过count和获取到的数据总条数对比,如果还有数据,那么页码变量要加一。

    界面

    下拉刷新上拉加载有一个很好用的库推荐https://github.com/CoderMJLee/MJRefresh

    reply
    0
  • Cancelreply