There are two ways to convert a parameter to a JSON-formatted string:
Way One:
Jsonobject Jo = new Jsonobject ();
Jo.put ("Certno", "522121198710114617");
Jo.put ("Certtype", "Identity_card");
String jostr = jo.tojsonstring ();
Way two:
map<string, object> map2 = new hashmap<string, object> ();
Map2.put ("Certno", "522121198710114617");
Map2.put ("Certtype", "Identity_card");
String jostr2 = jsonobject.tojsonstring (MAP2);
To convert a JSON format string to map:
/**
- Parse the jsonstring into map<string,object>>
- @param jsonstring
- @return
*/
public static map<string, object> Getmap (String jsonstring) {
map<string, object> map = new hashmap<string, object> ();
try {
Map = Json.parseobject (Jsonstring,map.class);
} catch (Exception e) {
E.printstacktrace ();
}
return map;
}
To take the desired parameter from the JSON object:
Object o = Json.tojson (response);
String str = o.tostring ();
Jsonobject Jo = Jsonobject.parseobject (str);
Jsonobject params = jo.getjsonobject ("params");
Java Background JSON operation