JSON and map convert to each other (using fastjson)

article directory

JSON String

    • to Map, get leaf node
    • Map to String String
  • JSON string to Map, get the leaf node

    fastjson has two ways:

    • json. parseObject (String, Class< T>)

    //JSON subclass

    • JSONObject.parseObject
    String str ={
     "sign": "sign",
     "data": {
      "type": "第二层",
      "order": {
       "test": "第三层"
    Map<String,String> parseObject = JSON.parseObject(str,Map.class);
    String sign=parseObject.get("sign");
    String data=String.valueOf(parseObject.get("data"));
    Map dataMap  = JSON.parseObject(data,Map.class);
    Map orderMap = (Map)dataMap.get("order"); 

    Map String String

    String str = JSONObject.toJSONString(testMap);

    – tools

    Read More: