<p>不得不说,JSON 格式的确是非常美妙的,速度快而且简化了很多操作</p><p>在 Android 下,Android SDK 已经为我们封装好了整个与 JSON 有关的操作,使用非常方便</p><p>以下就是一个标准的 JSON 请求的实现过程:</p><pre class="brush:java;toolbar:false">HttpPostrequest=newHttpPost(url);
//先封装一个JSON对象
JSONObjectparam=newJSONObject();
param.put("name","rarnu");
param.put("password","123456");
//绑定到请求Entry
StringEntityse=newStringEntity(param.toString());
request.setEntity(se);
//发送请求
HttpResponsehttpResponse=newDefaultHttpClient().execute(request);
//得到应答的字符串,这也是一个JSON格式保存的数据
StringretSrc=EntityUtils.toString(httpResponse.getEntity());
//生成JSON对象
JSONObjectresult=newJSONObject(retSrc);
Stringtoken=result.get("token");</pre><p></p><p></p>