RSS Feed for This PostCurrent Article

Java: Json-lib for JSON Object Transformation

I need a simple way to convert between JSON string and Java Map or Bean object, and Json-lib is the library that I used for this purpose.

JSON-lib is a java library for transforming beans, maps, collections, java arrays and XML to JSON and back again to beans and DynaBeans.
It is based on the work by Douglas Crockford in .

It supports bidirectional serialization for Maps, Collections, arrays (primitives, multidimensional), beans, DynaBeans, Enums and Annotations (jdk15 package only)

E.g. quoted from the website,

1. Map map = new HashMap();  
2. map.put( "name", "json" );  
3. map.put( "bool", Boolean.TRUE );  
4. map.put( "int", new Integer(1) );  
5. map.put( "arr", new String[]{"a","b"} );  
6. map.put( "func", "function(i){ return this.arr[i]; }" );  
8. JSONObject jsonObject = JSONObject.fromObject( map );  
9. System.out.println( jsonObject );  
0. // prints ["name":"json","bool":true,"int":1,"arr":["a","b"],"func":function(i){ return this.arr[i]; }]  

Popularity: 2% [?]

Trackback URL

RSS Feed for This PostPost a Comment