dadoneo 发表于 2013-1-28 09:42:33

Android 下使用 JSON 实现 HTTP 请求,外加几个示例!

不得不说,JSON 格式的确是非常美妙的,速度快而且简化了很多操作
在 Android 下,Android SDK 已经为我们封装好了整个与 JSON 有关的操作,使用非常方便

以下就是一个标准的 JSON 请求的实现过程:
HttpPost request = new HttpPost(url);// 先封装一个 JSON 对象JSONObject param = new JSONObject();param.put("name", "rarnu");param.put("password", "123456");// 绑定到请求 EntryStringEntity 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对象
页: [1]
查看完整版本: Android 下使用 JSON 实现 HTTP 请求,外加几个示例!