- 浏览: 359206 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
驭乐MJ:
你好,我卸载rar后,按命令执行安装unrar或者是p7zip ...
Ubuntu rar 乱码问题 -
郭建雄:
不错,受用了,谢谢你的分享 !
java线程中的interrupt,isInterrupt,interrupted方法 -
zuosheng:
...
用ViewFlipper实现各种切换动画 -
lxtkong-029:
原来一直不是很清楚,看来你的文章明白了,太感谢了!
java线程中的interrupt,isInterrupt,interrupted方法 -
ihopethatwell:
嗯,看到了,要在项目中添加jni
Ubuntu 10.04安装android NDK
分为两种;
一种是普通的,一种是带有数组形式的;
普通形式的:
服务器端返回的json数据格式如下:
{"userbean":{"Uid":"100196","Showname":"\u75af\u72c2\u7684\u7334\u5b50","Avtar":null,"State":1}}
分析代码如下:
// TODO 状态处理 500 200
int res = 0;
res = httpClient.execute(httpPost).getStatusLine().getStatusCode();
if (res == 200) {
/*
* 当返回码为200时,做处理
* 得到服务器端返回json数据,并做处理
* */
HttpResponse httpResponse = httpClient.execute(httpPost);
StringBuilder builder = new StringBuilder();
BufferedReader bufferedReader2 = new BufferedReader(
new InputStreamReader(httpResponse.getEntity().getContent()));
String str2 = "";
for (String s = bufferedReader2.readLine(); s != null; s = bufferedReader2
.readLine()) {
builder.append(s);
}
Log.i("cat", ">>>>>>" + builder.toString());
JSONObject jsonObject = new JSONObject(builder.toString()) .getJSONObject("userbean");
String Uid;
String Showname;
String Avtar;
String State;
Uid = jsonObject.getString("Uid");
Showname = jsonObject.getString("Showname");
Avtar = jsonObject.getString("Avtar");
State = jsonObject.getString("State");
带数组形式的:
服务器端返回的数据格式为:
{"calendar":
{"calendarlist":
[
{"calendar_id":"1705","title":"(\u4eb2\u5b50)ddssd","category_name":"\u9ed8\u8ba4\u5206\u7c7b","showtime":"1288927800","endshowtime":"1288931400","allDay":false},
{"calendar_id":"1706","title":"(\u65c5\u884c)","category_name":"\u9ed8\u8ba4\u5206\u7c7b","showtime":"1288933200","endshowtime":"1288936800","allDay":false}
]
}
}
分析代码如下:
// TODO 状态处理 500 200
int res = 0;
res = httpClient.execute(httpPost).getStatusLine().getStatusCode();
if (res == 200) {
/*
* 当返回码为200时,做处理
* 得到服务器端返回json数据,并做处理
* */
HttpResponse httpResponse = httpClient.execute(httpPost);
StringBuilder builder = new StringBuilder();
BufferedReader bufferedReader2 = new BufferedReader(
new InputStreamReader(httpResponse.getEntity().getContent()));
String str2 = "";
for (String s = bufferedReader2.readLine(); s != null; s = bufferedReader2
.readLine()) {
builder.append(s);
}
Log.i("cat", ">>>>>>" + builder.toString());
/**
* 这里需要分析服务器回传的json格式数据,
*/
JSONObject jsonObject = new JSONObject(builder.toString())
.getJSONObject("calendar");
JSONArray jsonArray = jsonObject.getJSONArray("calendarlist");
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObject2 = (JSONObject)jsonArray.opt(i);
CalendarInfo calendarInfo = new CalendarInfo();
calendarInfo.setCalendar_id(jsonObject2.getString("calendar_id"));
calendarInfo.setTitle(jsonObject2.getString("title"));
calendarInfo.setCategory_name(jsonObject2.getString("category_name"));
calendarInfo.setShowtime(jsonObject2.getString("showtime"));
calendarInfo.setEndtime(jsonObject2.getString("endshowtime"));
calendarInfo.setAllDay(jsonObject2.getBoolean("allDay"));
calendarInfos.add(calendarInfo);
}
总结,普通形式的只需用JSONObject ,带数组形式的需要使用JSONArray 将其变成一个list。
转自:http://www.cnblogs.com/tt_mc/archive/2011/01/04/1925327.html
发表评论
-
通过FutureTask设置超时,用于请求网络,执行任何异步超时任务
2013-10-10 15:53 0public class TestConnectTimeOu ... -
使用Eclipse调试Android Native Application
2013-07-08 21:31 0由于最近需要调试C++程序,以后都是暴力调试的,暴力调 ... -
Android新版NDK环境配置(免Cygwin)
2013-07-05 08:41 0前言:Android NDK r7及以上的版本已经集成 ... -
scroller 滚动效果
2013-04-25 14:22 0package com.testalaph; i ... -
点9 ondraw bitmap
2013-04-17 14:26 0private void init(Context ... -
点9 ondraw bitmap
2013-04-17 14:20 0点9图片ondraw画: private void ... -
通过activityGroup动态管理activity
2013-01-20 15:54 0// @Override // protected v ... -
scroller text view 滚动文字
2012-12-08 10:18 0package com.sc; import an ... -
android 截屏
2012-11-05 14:16 0//截屏2 private Bitmap jieping2 ... -
Android下Dialog及Activity屏蔽Home键详解
2011-12-13 11:53 0屏蔽其他键,重写onKeyDown Java代码 ... -
clipRect 介绍
2011-12-02 14:13 6680android的clip有以下两点疑问: Clip(剪切)的 ... -
android知识整理
2011-11-03 10:06 11. android单实例运行方 ... -
Android 使用junit测试
2011-08-05 16:18 921使用方式也非常的简单,只需要在AndroidManifest ... -
Android开发:调试工具集
2011-08-05 15:07 17931. 查看当前堆栈1) 功能:在程序中加入代码,使可以在log ... -
Android中attr自定义属性详解
2011-07-12 16:23 38648<LinearLayout xmlns:android= ... -
Drawable Mutations(Android Drawable 深入分析)
2011-07-11 11:08 1627Android's drawables对编写 ... -
检查系统是否安装某app
2011-07-11 10:45 924/** * Indicates whether th ... -
ImageView的scaletype属性
2011-07-07 13:21 817ImageView的属性android:scaleType ... -
Android UI --- 设置ProgressBar的颜色
2011-07-04 14:26 1247基本原理是在drawable目录中建立一个xml文件,描述一下 ... -
关于android的ListView优化
2011-06-24 16:58 10741.去除ListView的黑色间隔线 vie ...
相关推荐
深入剖析AJAX 解析JSON数据格式 抚尺而已 之,一人、一桌、一椅、一扇、一 忽然抚尺一下,群响毕绝。撤屏视
python学习(解析nginx埋点日志,解析json数据格式,url爬虫,redis集群删key)
C语言cJSON库的使用教程,解析json数据格式,适合刚毕业大学生学习。
阿里巴巴的一款java解析json的jar包,fastjson,方便简单实用!
该包适用于java开发中解析json数据格式的工具包,提供一系列API,方便开发者直接使用该包提供的api解析josn格式的数据。
C# 解析json格式数据为IList<T>
用jquery解析JSON数据的方法,作为jquery异步请求的传输对象,jquery请求后返回的结果是json对象,这里考虑的都是服务器返回JSON形式的字符串的形式,对于利用JSONObject等插件封装的JSON对象,与此亦是大同小异,这里...
C#的一个解析JSON的工具类,像java一样优雅的解析JSON数据,包含有JSONObject和JSONArray对象。 JSONObject json = new JSONObject(); json.Put("sex", "男"); json.Put("age", 123); json.Put("name", "张三"); ...
json数据格式java解析jar包 提供了方便的解析json数据格式的工具
json数据解析
c语言json数据格式解析 c语言json数据格式解析 c语言json数据格式解析
用jquery解析JSON数据的方法20110227用jquery解析JSON数据的方法20110227
使用解析JSON文件获取天气预报信息,并将不同城市的天气信息显示在主界面中,应用程序运行时界面如图1所示。单击其他城市按钮时,将显示相应城市对应的天气信息,如图2所示4.在模块对应的包名下创建JSON数据对应的...
1、生成Json数据 2、使用Gson解析Json数据(单个json对象、json数组和json对象内嵌json数组) // 这里有两篇好心人的博文,有详细的讲解 http://www.jb51.net/article/32547.htm ...
使用该方法可以轻松解析JSON数组,方便取出JSON数据
Delphi解析json数据。参考本方法可以用Delphi直接解析json数据,以弥补Delphi不能直接解析json数据的问题。
Qt利用UDP通信来传输JSON数据以及接收并解析JSON数据,UDP Server端采用Qt Widgets技术,UDP Client端采用Qt Quick技术。
这里进行介绍Gson解析复杂Json和简单Json的数据方式
如何生成JSON格式的数据 解析JSON格式的数据
JAVA在线接收解析JSON数据,引用的JSON类为 net.sf.json.JSONArray; net.sf.json.JSONObject;