1
您好我試圖發送一個ArrayList作爲POST請求從我的Android應用程序到服務器的參數。到目前爲止,我有這樣的代碼:如何發送ArrayList <Integer>作爲HTTPPOST請求中的UrlEncodedFormEntity?
HttpResponse response;
List<NameValuePair> postParams = new ArrayList<NameValuePair>(2);
postParams.add(new BasicNameValuePair("post[text]", text));
postParams.add(new BasicNameValuePair("post[common_comments]", String.valueOf(commonComments));
postParams.add(new BasicNameValuePair("post[wall_ids]", wallIds);
UrlEncodedFormEntity encodedParams;
try {
encodedParams = new UrlEncodedFormEntity(postParams);
post.setEntity(encodedParams);
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
但BasicNameValuePair只接收String作爲值。有沒有什麼辦法可以發送ArrayList作爲post [wall_ids]的值?
在此先感謝。
每當我過去遇到過這個問題時,我只是把它作爲一個逗號分隔的'String'與'Integer'值一起發送。我懷疑有更有效的方法來做到這一點;但它適用於我! – 2014-12-01 20:19:16
我的建議是:將您的數組轉換爲* JSON *對象(例如JSON數組)並將其作爲字符串發送 – Rami 2014-12-01 20:20:15