Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - When converting map to json in java, how to convert the integer numbers in the map into strings instead of integers after converting them to json.

There seems to be no special method, maybe I

When converting map to json in java, how to convert the integer numbers in the map into strings instead of integers after converting them to json.

There seems to be no special method, maybe I

When converting map to json in java, how to convert the integer numbers in the map into strings instead of integers after converting them to json.

There seems to be no special method, maybe I am not very talented,

The two methods I know:

map means that key-value pairs exist, so the types are It is fixed. We can apply for another map to traverse and replace the original map and convert it into a json string

String replacement, add double quotes using regular expressions: public?void?testJson() {

Map?map?=?new?HashMap();

map.put("aaa",?111);< /p>

String?json?=?JSON.toJSONString(map);

String?json1?=?json.replaceAll(":",?":\"");

p>

json1?=?json1.replaceAll("}",?"\"}");

System.out.println(json);

System. out.println(json1);

}