@ SuppressWarnings ( "unchecked" ) public static String map2JsonString ( Map < String , Object > map ) { IStringBuffer sb = new IStringBuffer ( ) ; sb . append ( ' ' ) ; for ( Map . Entry < String , Object > entry : map . entrySet ( ) ) { sb . append ( ' ' ) . append ( entry . getKey ( ) . toString ( ) ) . append ( "\": " ) ; Object obj = entry . getValue ( ) ; if ( obj instanceof List < ? > ) { sb . append ( list2JsonString ( ( List < Object > ) obj ) ) . append ( ' ' ) ; } else if ( obj instanceof Object [ ] ) { sb . append ( vector2JsonString ( ( Object [ ] ) obj ) ) . append ( ' ' ) ; } else if ( obj instanceof Map < ? , ? > ) { sb . append ( map2JsonString ( ( Map < String , Object > ) obj ) ) . append ( ' ' ) ; } else if ( ( obj instanceof Boolean ) || ( obj instanceof Byte ) || ( obj instanceof Short ) || ( obj instanceof Integer ) || ( obj instanceof Long ) || ( obj instanceof Float ) || ( obj instanceof Double ) ) { sb . append ( obj . toString ( ) ) . append ( ' ' ) ; } else { String v = obj . toString ( ) ; int last = v . length ( ) - 1 ; if ( v . length ( ) > 1 && ( ( v . charAt ( 0 ) == ' ' && v . charAt ( last ) == ' ' ) || ( v . charAt ( 0 ) == ' ' && v . charAt ( last ) == ' ' ) ) ) { sb . append ( v ) . append ( ' ' ) ; } else { sb . append ( ' ' ) . append ( v ) . append ( "\"," ) ; } } } if ( sb . length ( ) > 1 ) { sb . deleteCharAt ( sb . length ( ) - 1 ) ; } sb . append ( ' ' ) ; return sb . toString ( ) ; }
map to json string