我想咨询一件事, 其实,这是你的一个建议。 我有一个使用 spring 3.0、JSF 2.0、Hibernate 和 PrimeFaces 创建的项目。 这个项目还有一个移动平台, 问题就从这里开始。 您对连接 android 平台以获取和发送数据有什么建议? android平台的功能与web平台相同。 JSON 或 XML 格式的数据(Web 服务)
最佳答案
只需使用您自己的 Oauth postmethod 即可返回 JSONObject。发送 POST 和 GET 请求很容易做到。
例如...
public static HttpResponse SendGet(String Url, HashMap<String,
String> hm, DefaultHttpClient httpClient) {
HttpResponse response = null;
if (hm == null) return null;
HttpGet getMethod = new HttpGet(Url);
response = httpClient.execute(getMethod);
return response;
}
然后你可以使用类似于...的方式处理httpresponse
BasicResponseHandler handler = new BasicResponseHandler();
String response = handler.handleResponse(httpresponse);
j = new JSONObject(response);
因此您可以在获取请求中添加 token 和用户ID
Url = Url+"?token="token; //etc
您还可以轻松地将其转换为帖子请求并通过帖子正文发送 oauth 参数。网上有大量教程/信息。
关于java - Android、Spring 和 Json 一般问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7923304/