JsonTools是一个不错的JSON序列化和反序列化功能包,在这里可以下载到它:http://jsontools.berlios.de/。
它有以下功能:
- Parser: Parse JSON text files and convert these to a Java model.
- Renderer: Render a Java representation into text.
- Serializer: Serialize plain POJO clusters to a JSON representation. The goal is to provide a serializing mechanism which can cope with all kinds of Java datastructures (recursion, references, primitive types, ...) .
- Mapper: Map POJO to JSON, this time the JSON text should be as clean as possible. This tool is the best choice when data has to be communicated between Java and other programming languages who can parse JSON.
- Validator: Validate the contents of a JSON file using a JSON schema.
如何使用呢?请参考下面我写的示例代码:
package test;
import java.io.StringReader;
import test.vo.ClientTicketOrder;
import test.vo.TicketItem;
import antlr.RecognitionException;
import antlr.TokenStreamException;
import com.sdicons.json.mapper.JSONMapper;
import com.sdicons.json.mapper.MapperException;
import com.sdicons.json.model.JSONValue;
import com.sdicons.json.parser.JSONParser;
public class TestJsonTools {
/**
* @param args
* @throws MapperException
* @throws RecognitionException
* @throws TokenStreamException
*/
public static void main(String[] args) throws MapperException, TokenStreamException, RecognitionException {
ClientTicketOrder order = new ClientTicketOrder();
order.setClientOrderNo("0812333");
TicketItem tItem = new TicketItem();
tItem.setPnr("UY8YG");
order.setTicketItems(new TicketItem[]{tItem});
//JavaBean to JSON
JSONValue jsonValue = JSONMapper.toJSON( order );
String jsonStr = jsonValue.render(false);
System.out.println(jsonStr);
//JSON to JavaBean
JSONParser parser = new JSONParser(new StringReader(jsonStr));
ClientTicketOrder u = (ClientTicketOrder) JSONMapper.toJava(parser.nextValue(), ClientTicketOrder.class);
System.out.println(u.getClientOrderNo() + " " + u.getTicketItems()[0].getPnr());
}
}
分享到:
相关推荐
Json序列化和反序列化 包含.NET各版本Newtonsoft.Json.dll 以及程序集使用方法详细说明
一个c#的json序列化和反序列化类,调用很简单
Jackson-datatype-money - 开源的Jackson模块,支持Java货币数据类型的JSON序列化和反序列化
只要对json和序列化和反序列化总结,以及代码的案例:我们很多时候会涉及到几个序列化对象的使用:DataContractJsonSerializer,JavaScriptSerializer 和 Json.NET。
Java Json序列化与反序列化
C#-JSON序列化和反序列化辅助类
JsonTools是一个不错的JSON序列化和反序列化功能包
C++ JSON 序列化与反序列化 相关的博客文章见:http://blog.csdn.net/TragicGuy
纯C语言编写的json库,可以进行json序列化和反序列化.zip
/// Json序列化与反序列化方法封装类 /// public static class JsonConvert { /// /// 序列化模型对象为Json /// /// 模型类型 /// 模型对象 /// <returns></returns> public static string GetJson(T...
Newtonsoft.Json 是一款 .NET 平台中开源的 JSON 序列化和反序列化类库
简而言之,这是一个可以用于.NET的Json辅助工具类。它可以将对对象序列化为json字符串,或者将json字符串反序列化。
Json序列化与反序列化
jackson json序列化 json反序列化 jar包 直接下载拷贝到项目中buildpath即可使用
10万次序列化,1万次反序列化,毫秒。 阿里序列化时间 1122 1054 1115 阿里反序列化时间 409 423 412 HZS序列化时间 884 864 880 HZS反序列化时间 392 375 394 JAVA7版已经逼近阿里的速度,JAVA8版利用了闭包技术...
delphi_JSON序列化反序列化
极好的序列化与发序列化代码。可以处理array集合,数组或者单个对象等的序列化与反序列化。