简体   繁体   English

使用RxJava从翻新响应中获取N数据

[英]Fetch N Data from Retrofit Response using RxJava

My API is sending a response similar to the snippet below. 我的API发送的响应类似于以下代码段。 The dataList contains 100 items. dataList包含100个项目。 I want to load it 10 items at a time, instead of waiting for all the items to fetch. 我想一次加载10个项目,而不是等待所有项目提取。 Can anyone help me out with this, How can i achieve this with RxJava. 任何人都可以帮我解决这个问题,如何使用RxJava实现这一点。 ( I am using Retrofit for Networking ) (我正在使用联网改造)

someresponse{ "status":true, "dataList":[ .....] } someresponse {“ status”:true,“ dataList”:[.....]}

You have misunderstanding how JSON schema work. 您对JSON模式的工作方式有误解。 To be able to parse JSON you SHOULD wait for the entire response body. 为了能够解析JSON,您应该等待整个响应主体。

While that said, you still can override read method as described in the answer. 虽然如此,您仍然可以按照答案中的说明重写read方法。 You will need to parse JSON manually, putting in the stack curly braces until you meet dataList: { and the end of the item in it } , but there's no guaranty the JSON won't be malformed. 您将需要手动解析JSON,将大括号放在堆栈中,直到遇到dataList: {和其中的项目末尾}为止,但没有保证JSON不会格式错误。 At the end of the day, it's definitely not worth it. 归根结底,这绝对不值得。

Also, note that JSON data shouldn't be that heavy as files or smth. 另外,请注意,JSON数据不应像文件或文件那么重。 If you have 1Mb + of JSON it means you're doing something wrong and you need to redesign your backend API. 如果您具有JSON的1Mb +,则表示您做错了,您需要重新设计后端API。 Otherwise, you shouldn't be wasting time on this issue. 否则,您不应该在这个问题上浪费时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM