什么是json
json是一个轻量级数据交换格式,很容易被人们读写,很容易被机器解析和生成。它建立在js的一个子集之上,json是一个文本格式,它独立于具体的语言,但是使用了和c类似的约定。包括c、c++、c#、java、js、perl、perl、等。
这些属性使json成为理想的数据交互格式。(以上描述来源于json官方网站)
【1】到http://json-lib.sourceforge.net/下载 json-lib-2.2.1-jdk15.jar(08-5-6日可用版本)
同时项目中需要
- jakarta commons-lang 2.3
- jakarta commons-beanutils 1.7.0
- jakarta commons-collections 3.2
- jakarta commons-logging 1.1
- ezmorph 1.0.4
【2】action中引入
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;解析代码如下
//###############
JSONArray jsonArray;
jsonArray = JSONArray.fromObject(jsonString);
java.util.Iterator<JSONObject> iter = jsonArray.iterator();
while(iter.hasNext()){
EvPlayContent content = new EvPlayContent();
JSONObject jsobj = iter.next();
content.setDisplayMethod(jsobj.get("displayMethod").equals("")?null:jsobj.getInt("displayMethod"));
content.setPlayTime(jsobj.get("playTime").equals("")?null:jsobj.getInt("playTime"));
content.setSequenceNum(jsobj.getInt("sequenceNum"));
content.setVolumn(jsobj.get("volumn").equals("")?null:jsobj.getInt("volumn"));
Integer mid = jsobj.getInt("mId");
}