不得不說,JSON 格式的確是非常美妙的,速度快而且簡化了很多操作
在 Android 下,Android SDK 已經為我們封裝好了整個與 JSON 有關的操作,使用非常方便
以下就是一個標准的 JSON 請求的實現過程:
- 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對象