process json string

1 Get the key value in the json string

1.1 java way

import com.alibaba.fastjson.JSON;
import java.util.HashMap;


public class JsonTool {

    /**
     *
     * @param json_str 传入的json串
     * @return json串最外层的key
     */
    public static Object[] getKeys(String json_str) {
        HashMap map;
        try {
            map = JSON.parseObject(json_str, HashMap.class);
        } catch (Exception e) {
            return null;
        }
        return map.keySet().toArray();
    }

}


Guess you like

Origin blog.csdn.net/weixin_40829577/article/details/123357357