简体   繁体   English

获取变化很大的远程数据的最佳方法

[英]Best way to get remote data that changes a lot

There are 3+ apps which collect parameters in the form of one string, like "Peter", "Jane", "Mary", etc. At the moment I keep this parameters in String[] array. 有3个以上的应用程序以一个字符串的形式收集参数,如“Peter”,“Jane”,“Mary”等。目前我将这些参数保存在String[]数组中。 However, the data needs to be changed a lot so every few days I have to amend strings, recompile APKs and publish it. 但是,数据需要进行大量更改,因此每隔几天我就必须修改字符串,重新编译APK并发布它。 Just waist of time. 只是时间的腰部。

What should be the simplest way to keep this data in a remote file (NOT database), maybe text file, so that the apps can download list of parameters on need? 什么应该是将这些数据保存在远程文件(非数据库)中的最简单方法,也许是文本文件,以便应用程序可以根据需要下载参数列表? My idea is to change this file just once, upload it to some remote server and then the apps download parameters automatically. 我的想法是只更改此文件一次,将其上传到某个远程服务器,然后自动下载应用程序参数。 This way I would not have to recompile and republish the APKs. 这样我就不必重新编译和重新发布APK。

If the text file is the simplest solution, what should be the form of it? 如果文本文件是最简单的解决方案,它的形式应该是什么? For example, should I write parameters like this 例如,我应该写这样的参数

Peter, Jane, Mary, ... 彼得,简,玛丽,......

Or in some other form? 还是以其他形式?

Is there a need for some layer between this text file and Android app, like when we make layer on the remote server to grab data from database? 这个文本文件和Android应用程序之间是否需要一些层,比如我们在远程服务器上创建图层以从数据库中获取数据? Or I can simply grab data directly from this remote text file?! 或者我可以直接从这个远程文本文件中获取数据?!

Well the delivery mechanism could be a simple HTTP GET your app performs to a web server you control. 那么传递机制可能是您的应用程序对您控制的Web服务器执行的简单HTTP GET。 It could be as simple as http://myhost/names.txt . 它可以像http://myhost/names.txt一样简单。

The data format depends on what you want to do. 数据格式取决于您想要做什么。 The super simple solution would be a text file with a different name on each line: 超级简单的解决方案是每行上具有不同名称的文本文件:

Peter
Jane
Mary

Or, you could serve up JSON from the server and parse it on your client. 或者,您可以从服务器提供JSON并在客户端上解析它。

{ "names": [ "Peter", "Jane", "Mary" ] }

The JSON solution would be more extendable, should you wish to add more values in future, eg: 如果您希望将来添加更多值,JSON解决方案将更具扩展性,例如:

{ "names": [ "Peter", "Jane", "Mary" ], 
  "lastnames": [ "Smith", "Johnston", "Cumberbatch" ] }

Really depends entirely on what you're comfortable with and what your situation calls for. 真的完全取决于你感到满意和你的情况需要什么。

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

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