Android 下使用 JSON 实现 HTTP 请求,外加几个示例!
2013-02-14 10:00
791 查看
不得不说,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");
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 下,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");
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 请求,外加几个示例!
- Android 下使用 JSON 实现 HTTP 请求,外加几个示例!
- Android 下使用 JSON 实现 HTTP 请求,外加几个示例!
- Android 下使用 JSON 实现 HTTP 请求,外加几个示例!
- Android 下使用 JSON 实现 HTTP 请求,外加几个示例!
- Android 下使用 JSON 实现 HTTP 请求
- Android 下使用 JSON 实现 HTTP 请求
- Android 下使用 JSON 实现 HTTP 请求
- Android 下使用 JSON 实现 HTTP 请求
- Android中基于HTTP的通信技术(5)Google开源库 使用 Volley 实现 JSON 字符串请求
- Android 下使用 JSON 实现 HTTP 请求
- Android 下使用 JSON 实现 HTTP 请求
- android(21)(使用HttpURLConnection,HttpClient和AsyncHttpClient分别实现post和get请求数据)
- Android HTTP实例 使用GET方法和POST方法发送请求(通过Apache接口实现)
- Android--使用原生技术实现ListView(原生技术实现网络异步请求,解析json数据)
- Android HttpURLconnection使用POST请求参数是json
- Android中使用HttpURLConnection和HttpClient实现GET和POST请求访问网络
- 使用$.getJSON实现跨域ajax请求示例代码
- Android中使用HttpURLConnection实现GET POST JSON数据与下载图片
- Android中使用HttpURLConnection实现GET POST JSON数据与下载图片