本文目錄一覽:
- 1、Android 怎麼把json數據傳遞到下個頁面
- 2、Android 發送JSON數據問題
- 3、Android利用Json來進行網路數據傳輸
- 4、Android如何傳輸參數給一個url介面 參數是json格式
- 5、android 如何用json傳遞文件
Android 怎麼把json數據傳遞到下個頁面
可以通過intent將其序列化傳遞
1,可以傳遞string,下個頁面啟動後可以再通過string創建json對象
2,如果只有少數幾個key-value,可以直接在intent中分別傳遞,可以免去重構json對象的工作。
Android 發送JSON數據問題
你確定你的URL沒問題,老是糾結參數,不管什麼參數伺服器肯定能收到啊,只是解析不出來而已
Android利用Json來進行網路數據傳輸
有點暈暈的,如果你是傳多個對象[{id:1,name:”tom”,age:”20″},{id:2,name:”tom”,age:”20″}]
怎麼搞成伺服器請求客戶端了??不是客戶端請求伺服器嗎?
一般JSON對應json都是通過id來對應的,我就是這樣對應的
Android如何傳輸參數給一個url介面 參數是json格式
一般傳輸參數使用json類型或者map類型都是使用post方法。
使用json數據格式發送信息向伺服器端:
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpPost = new HttpPost(BASIC_URL + url);
ListNameValuePair nameValuePair = new ArrayListNameValuePair();
JSONObject jsonObject = new JSONObject();
JSONObject jsonObject2 = new JSONObject();
jsonObject.put(“uemail”, userbean.getEmail());
jsonObject.put(“password”, userbean.getPassword());
jsonObject2.put(“userbean”, jsonObject);
nameValuePair.add(new BasicNameValuePair(“jsonString”, jsonObject
.toString()));
Log.i(“lifeweeker”, jsonObject2.toString());
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
}
android 如何用json傳遞文件
先發現json可以直接傳遞個Object對象。開始時打算將文件讀取成byte[]數組,然後再將byte轉換為object來傳遞。通過如下方法[*]public Object toObject (byte[] bytes) { [*] Object obj = null; [*] try { [*] ByteArrayInputStream bis = new ByteArrayInputStream (bytes); [*] ObjectInputStream ois = new ObjectInputStream (bis); [*] obj = ois.readObject(); [*] ois.close(); [*] bis.close(); [*] } catch (IOException ex) { [*] ex.printStackTrace(); [*] } catch (ClassNotFoundException ex) { [*] ex.printStackTrace(); [*] } [*] return obj; [*] } 但測試發現調用這個函數時發生錯誤java.io.StreamCorruptedException,不知道為什麼。而後又想能不能直接傳遞個File對象,例如:File file = new File(xxx);jsObj.put(“key”, file);File file2 = jsObj.get(“key”);請問這樣這樣能不能行通?因為發現很多跨進程傳遞對象數據都必須要求對象是序列化的。所以此處很疑惑通過json方法是否也需要這個File對象要序列化什麼的。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/301500.html