简体   繁体   English

Swift - 如何每天从 JSON 文件中获取几个对象?

[英]Swift - How to fetch just a few objects from a JSON file everyday?

I created a json file with 900 objects inside and want to download 30 objects daily.我创建了一个 json 文件,里面有 900 个对象,我想每天下载 30 个对象。 How can I do this?我怎样才能做到这一点?

If everything is in a single file, and you are downloading that file, the answer is that you can't.如果所有内容都在一个文件中,并且您正在下载该文件,那么答案是您不能。

If you must use file downloading, you would need to break up your content into smaller files and download a few each day.如果您必须使用文件下载,则需要将您的内容分解为较小的文件并每天下载几个。 (Maybe 900 separate files and download 30 of those files, or maybe divide your JSON into 30 files of 30 objects each, and download a single file a day. (可能有 900 个单独的文件并下载其中的 30 个文件,或者可能将您的 JSON 分成 30 个文件,每个文件有 30 个对象,每天下载一个文件。

Alternately, set up your JSON behind a server API that responds to GET requests with a query parameter that lets you specify which objects you want.或者,在服务器 API 后面设置 JSON,该服务器使用查询参数响应 GET 请求,让您指定所需的对象。 Then have your app submit a GET request each day for the 30 objects it wants to download.然后让您的应用每天为它要下载的 30 个对象提交一个 GET 请求。 (This is probably the best option.) (这可能是最好的选择。)

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

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