fastjson 은 json 이 jsonArray 인지 jsonObject 인지 몇 가지 방식 으로 판단 합 니 다.

3544 단어 자바fastjsonjson
1.문자열 캡 처 판단 사용 문자열 의 시작 위치 와 끝 위치
 public static void main(String[] args) {
        String dataStr = "['ces':'dd']";
        if (dataStr.startsWith("[") && dataStr.endsWith("]")) {
            System.out.println("  jsonArray");
        } else {
            System.out.println("  jsonObject");
        }
    }

2.JSON.parse 로 판단
   Object object = JSON.parse(dataStr);
        if (object instanceof JSONArray) {
            System.out.println("  jsonArray");
        } else {
            System.out.println("  jsonObject");
        }


완성 하 다.

좋은 웹페이지 즐겨찾기