public static String mapToJSONString ( Map < ? , ? > map ) { if ( map == null || map . size ( ) == 0 ) { return "{}" ; } StringBuilder sb = new StringBuilder ( "{" ) ; for ( Object o : map . entrySet ( ) ) { Entry < ? , ? > e = ( Entry < ? , ? > ) o ; buildAppendString ( sb , e . getKey ( ) ) . append ( ' ' ) ; buildAppendString ( sb , e . getValue ( ) ) . append ( ' ' ) . append ( ' ' ) ; } return sb . delete ( sb . length ( ) - 2 , sb . length ( ) ) . append ( ' ' ) . toString ( ) ; }
Map to json string string .