java 如何从 RESTful 服务器获取 JSON 内容到 Android 客户端?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6611663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:36:55  来源:igfitidea点击:

How to get JSON content from a RESTful server to a Android client?

javaandroidweb-servicesjsonrest

提问by jan

I've built a REST server that automatically retrieves data from my database and returns it as JSON. I want to know, how I can get this JSON content to my mobile and turn it into a string so that I can store this in the mobile's database.

我构建了一个 REST 服务器,它自动从我的数据库中检索数据并将其作为 JSON 返回。我想知道,如何将这个 JSON 内容发送到我的手机并将其转换为字符串,以便我可以将其存储在手机的数据库中。

回答by David Olsson

First you need to be able to parse your JSON string. For a simple parser I gave an answer earlier here: getting Json result in AndroidJust parse through the list and add them to the database. There are different database tutorials out there.

首先,您需要能够解析 JSON 字符串。对于一个简单的解析器,我之前在这里给出了一个答案: 在 Android 中获取 Json 结果只需解析列表并将它们添加到数据库中。那里有不同的数据库教程。

Database tutorial: http://www.vogella.de/articles/AndroidSQLite/article.html

数据库教程:http: //www.vogella.de/articles/AndroidSQLite/article.html

To make it as easy as possible try to find out small tutorials for different sub tasks like REST to JSON and database handler.

为了尽可能简单,尝试找出不同子任务(如 REST 到 JSON 和数据库处理程序)的小教程。

Here is a tutorial for JSON parsing from a REST webservice: http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/
Here is another more simple JSON example:
http://inchoo.net/mobile-development/android-development/simple-android-json-parsing-example-with-output-into-listactivity/

这是从 REST 网络服务解析 JSON 的教程:http: //www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/
这是另一个更简单的 JSON 示例:
http://inchoo.net/mobile-development/android-development/simple-android-json-parsing-example-with-output-into-listactivity/