JSON01_资料
1、
资料网址:
http://blog.csdn.net/vincent_czz/article/details/7333977
http://blog.csdn.net/huangwuyi/article/details/5412500
下载网址:https://sourceforge.net/projects/json-lib/files/
在线API:http://json-lib.sourceforge.NET/apidocs/jdk15/index.html
2、
异常处理:http://www.xuebuyuan.com/2158801.html
2.1、异常:
在“JSONObject.fromObject(...)”处报错:“Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException”
2.2、处理:
项目中导入了 json-lib 包,但是在运行如下代码的时候还是出现了如下错误,究其原因是因为缺包,缺了如下5个包:
commons-beanutils-1.8.3
commons-lang-2.6 (注:导入最新的 3.1 版本会继续报上面的错误)
commons-collections-3.2.1
commons-logging-1.1.1
ezmorph-1.0.6
2.3、我现在使用的相关包分别为:(它们 都是从各自的官网上下载下来的)
(1)、json-lib-2.4-jdk15.jar
(2)、commons-beanutils-1.8.3.jar
(3)、commons-collections-3.2.2.jar
(4)、commons-lang-2.6.jar
(5)、commons-logging-1.2.jar
(6)、ezmorph-1.0.6.jar
3、ZC 测试代码
package test; import java.util.Iterator;
import net.sf.json.*; public class Ttest03
{
public static void main(String[] args)
{
String jsonString = "{\"FLAG\":\"flag\",\"MESSAGE\":\"SUCCESS\",\"name\":[{\"name\":\"jack\"},{\"name\":\"lucy\"}]}";
try
{
JSONObject result = JSONObject.fromObject(jsonString);//转换为JSONObject
JSONArray nameList = result.getJSONArray("name");//获取JSONArray
int iSize = nameList.size();
System.out.println("iSize : "+iSize); String strName01 = "";
for(int i = 0; i < iSize; i++)//遍历JSONArray
{
JSONObject oj = nameList.getJSONObject(i);
strName01 = oj.getString("name");
System.out.println("["+Integer.toString(i)+"] : name : "+strName01);
}
Iterator<?> itKeys = result.keys();
String aa2 = "";
String bb2 = null;
while(itKeys.hasNext())//遍历JSONObject
{
bb2 = (String) itKeys.next().toString();
aa2 = result.getString(bb2);
System.out.println(bb2+" -- "+aa2);
}
//} catch (JSONException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
4、
5、
最新文章
- Webstorm 下的Angular2.0开发之路
- 《统计推断(Statistical Inference)》读书笔记——第1章 概率论
- 移植u-boot.2012.04.01
- Hibernate4搭建Log4J日志管理(附Log4j.properties配置详解)
- Python Tutorial学习(十一)-- Brief Tour of the Standard Library – Part II
- 关于xml作为模板的配置服务系统开发
- linux下清理系统垃圾
- ArcSDE for Oracle表空间管理——暂时(TEMP)表空间
- PHP中的数组方法及访问方法总结
- Swift语言指南(二)--语言基础之注释和分号
- Java笔记:内部类
- C语言中数组转化为字符串的方法
- 中国四大骨干网与十大ISP服务商
- MapReduce实现ReduceSideJoin操作
- java知识点3
- 解决jqueryeasyUI dialog 弹出窗体超出浏览器,导致不能关闭的bug
- POJ2431 Expedition 贪心
- Jquery easyui 重置按钮,easyui 清空表单,Jquery easyui 重置表单
- laravel5.3的多用户登录,经过验证laravel5.4可用【转帖】
- scala 学习笔记五 foreach, map, reduce