標籤:
不得不說,JSON 格式的確是非常美妙的,速度快而且簡化了很多操作
在 Android 下,Android SDK 已經為我們封裝好了整個與 JSON 有關的操作,使用非常方便
以下就是一個標準的 JSON 請求的實現過程:
[java] view plaincopyprint?
- HttpPost request = new HttpPost(url);
- // 先封裝一個 JSON 對象
- JSONObject param = new JSONObject();
- param.put("name", "rarnu");
- param.put("password", "123456");
- // 綁定到請求 Entry
- StringEntity se = new StringEntity(param.toString());
- request.setEntity(se);
- // 發送請求
- HttpResponse httpResponse = new DefaultHttpClient().execute(request);
- // 得到應答的字串,這也是一個 JSON 格式儲存的資料
- String retSrc = EntityUtils.toString(httpResponse.getEntity());
- // 產生 JSON 對象
- JSONObject result = new JSONObject( retSrc);
- String token = result.get("token");
android下支援JSON的遠端存取(推薦此BLOG):http://marshal.easymorse.com/archives/1707
關於android JSON寫入類--JsonWriter,輕鬆產生JSON格式的資料:http://disanji.net/2011/03/05/android-3-0-json-jsonwriter/
android JSON解析範例程式碼,每日維基widget:http://www.android123.com.cn/androidkaifa/664.html
用戶端向伺服器端發送資料,一種是在url中帶參數,一種是json資料發送方式(小陌):http://henzil.easymorse.com/?p=241
android訪問PHP取回JSON資料:http://blog.lrenwang.com/post/114/
如何用android JSON對象發送一個請求:
http://cn.webdiscussion.info/question/3027066/如何發送一個請求在與Android-JSON對象
Android 下使用 JSON 實現 HTTP 要求,外加幾個樣本!