簡體   English   中英

Android,Spring和Json的一般問題?

[英]Android,Spring and Json General Questions?

我想咨詢一件事,實際上是您的建議。 我有一個使用spring 3.0,JSF 2.0,Hibernate和PrimeFaces創建的項目。 這個項目也有一個移動平台,問題從這里開始。 您對連接android平台獲取和發送數據有何建議? android平台的功能與網絡平台相同。 數據為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);

因此,您可以添加的內容是獲取請求的令牌和用戶ID

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

您也可以輕松地將其轉換為發布請求,並通過發布正文發送oauth參數。 在線有大量的教程/信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM