简体   繁体   English

Android,Spring和Json的一般问题?

[英]Android,Spring and Json General Questions?

I want to consult a thing, Actually,It is a suggestion from you . 我想咨询一件事,实际上是您的建议。 I have a project that was created with spring 3.0,JSF 2.0,Hibernate and PrimeFaces. 我有一个使用spring 3.0,JSF 2.0,Hibernate和PrimeFaces创建的项目。 This project has a mobile platform also, Problem is starting here. 这个项目也有一个移动平台,问题从这里开始。 What is your suggestion to connect android platform for getting and sending data? 您对连接android平台获取和发送数据有何建议? android platform's functionally is the same as web platform's. android平台的功能与网络平台相同。 Data as JSON or XML(Web Service) 数据为JSON或XML(Web服务)

Just use your own Oauth postmethod which would return a JSONObject. 只需使用您自己的Oauth postmethod,该方法将返回JSONObject。 sending POST and GET requests are easy enough to do. 发送POST和GET请求很容易做到。

for example... 例如...

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;
}

Then you can handle the httpresponse with somethign similar to... 然后,您可以使用类似于...的方式处理httpresponse。

BasicResponseHandler handler = new BasicResponseHandler();
String response = handler.handleResponse(httpresponse);
j = new JSONObject(response);

So things you could add are token and userid to the get request 因此,您可以添加的内容是获取请求的令牌和用户ID

Url = Url+"?token="token; //etc 

also you can easily convert this to a post request and send the oauth params via the post body. 您也可以轻松地将其转换为发布请求,并通过发布正文发送oauth参数。 There is plenty of tutorials/info available online. 在线有大量的教程/信息。

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

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