導航:首頁 > 操作系統 > android上傳json數據

android上傳json數據

發布時間:2023-02-02 22:19:59

android Studio用httpPost向伺服器傳json數據,StringEntity不存在,求高手幫忙

你最後具體怎麼解決?

㈡ Android利用Json來進行網路數據傳輸

有點暈暈的,如果你是傳多個對象[{id:1,name:"tom",age:"20"},{id:2,name:"tom",age:"20"}]
怎麼搞成伺服器請求客戶端了??不是客戶端請求伺服器嗎?
一般JSON對應json都是通過id來對應的,我就是這樣對應的

㈢ android volley stringrequest post中的getparams怎麼把json數據提交上去

1.客戶端以普通的post方式進行提交,服務端返回字元串
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST,httpurl,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "response -> " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, error.getMessage(), error);
}
}) {
@Override
protected Map<String, String> getParams() {
//在這里設置需要post的參數
Map<String, String> map = new HashMap<String, String>();
map.put("name1", "value1");
map.put("name2", "value2");
return params;
}
};
requestQueue.add(stringRequest);

2.客戶端以json串的post請求方式進行提交,服務端返回json串
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
Map<String, String> map = new HashMap<String, String>();
map.put("name1", "value1");
map.put("name2", "value2");
JSONObject jsonObject = new JSONObject(params);
JsonRequest<JSONObject> jsonRequest = new JsonObjectRequest(Method.POST,httpurl, jsonObject,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "response -> " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, error.getMessage(), error);
}
})
{
//注意此處override的getParams()方法,在此處設置post需要提交的參數根本不起作用
//必須象上面那樣,構成JSONObject當做實參傳入JsonObjectRequest對象里
//所以這個方法在此處是不需要的
// @Override
// protected Map<String, String> getParams() {
// Map<String, String> map = new HashMap<String, String>();
// map.put("name1", "value1");
// map.put("name2", "value2");

// return params;
// }

閱讀全文

與android上傳json數據相關的資料

熱點內容
jpeg轉成pdf在線 瀏覽:436
pythonwinreg下載 瀏覽:100
伺服器獲得ftp地址 瀏覽:596
但是編譯確找不到 瀏覽:620
mc後處理如何加密一機一碼 瀏覽:137
歌曲伺服器異常怎麼辦 瀏覽:779
git編譯參數 瀏覽:371
phpbcmath擴展 瀏覽:120
加密漢字五筆 瀏覽:371
怎麼把本地的網站部署到伺服器上 瀏覽:667
大專單片機試題 瀏覽:874
滑鼠文件夾消失 瀏覽:550
pdf軟體注冊碼 瀏覽:832
qt如何對數字加密 瀏覽:565
程序員職業未來 瀏覽:674
怎麼找程序員做網站 瀏覽:615
pdf轉換成xps 瀏覽:85
如何查看伺服器登錄的密碼是什麼原因 瀏覽:452
x21加密的照片怎麼找 瀏覽:781
天乾地支的演算法今年是什麼年 瀏覽:613