To convert map to json in android, you need to download jackson package, download address:
http://www.java2s.com/Code/Jar/j/Downloadjacksonall199jar.htm
After the download is complete, unzip it and import it into your project. First switch to the project view
Put the jar package into the lib folder
Then right-click and select Add As Library below
Finally, here comes the point
Map<String, String> map = new HashMap<String, String>();
//Put the data in
map.put("username", "user123");
map.put("password", "123456");
map.put("phone", "13800000000");
map.put("email", "[email protected]");
//objectMapper belongs to the Jackson package, you must import the Jackson package to use
ObjectMapper json = new ObjectMapper ();
try {
String zhuanma = json.writeValueAsString(map);
//Print the result in the console
Log.d("Converted result",zhuanma);
} catch (IOException e) {
e.printStackTrace();
}