`

判断字符串是不是JSONObject 或 JSONArray

 
阅读更多

方法1

 

 Object json = new JSONTokener(jsonValue).nextValue();

 

        if (json instanceof JSONObject) {

 

} else if (json instanceof JSONArray) {

 

}

 

方法2

public static boolean isJson(String value) {

    try {

      new org.json.JSONObject(value);

    } catch (org.json.JSONException e) {

      return false;

    }

    return true;

  }

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics