java的json解析类库使用示例
本文导语: 开源项目主页:https://github.com/dongfangshangren/Zson 代码如下:import java.util.List;import java.util.ArrayList;import java.lang.reflect.Type;import org.zson.JsonSerializer;import org.zson.TypeReference;import org.zson.JsonDeserializer; import test.bean.SomeBean; public class TestZson{...
开源项目主页:https://github.com/dongfangshangren/Zson
import java.util.List;
import java.util.ArrayList;
import java.lang.reflect.Type;
import org.zson.JsonSerializer;
import org.zson.TypeReference;
import org.zson.JsonDeserializer;
import test.bean.SomeBean;
public class TestZson{
public static void main(){
//Serialize
List list=new ArrayList();
String json=new JsonSerializer().prettyFormat(2).ignoreNull(false)
.dateFormat("yyyy-MM-dd").serialize(list);
//Deserilize
Type type=new TypeReference(){}.getType();
List result=(List)new JsonDeserializer().deserialize(json,type);
}
}