Java method for quickly converting a map to json format

  • 2020-04-01 03:58:38
  • OfStack

In everyday use, we typically encounter map to json, which can take a lot of time to iterate over, but we have jars like this


The method *** is undefined for the type JSONObject Lack of which package ------
json-lib.jar

Still, you need a dependent jar or you'll get an error


java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher

Dang dang & na;   Jar package is ezmorph - * * *. The jar
 
Here's how we do it

JSONSerializer. ToJSON (map object)

Let's say our map object is


{time=2015/04/10, carNum= Beijing A2212, mark= The fender is damaged. The headlight is damaged , billNum=100232113213R}

The result after converting to json is

{"time":"2015/04/10","carNum":" Beijing A2212","mark":" The fender is damaged. The headlight is damaged ","billNum":"100232113213R"}

Isn't super loving


Related articles: