Determine the JSON string return type Object or array

Source: Internet
Author: User

    public enum Json_type {        /**         * jsonobject */        json_type_object,        /**         *         Jsonarray        * * Json_type_array,        /**         * is not a JSON-formatted string */        json_type_error    }    /***     *     * Gets the JSON type     * Judgment Rule     * Determines whether the first letter is {or [if none is not a JSON-formatted text     *     * @param str     * @return    * * public static Json_type Getjsontype (String str) {        if (Pubstring.isempty (str)) {            return json_type. Json_type_error;        }        Final char[] Strchar = str.substring (0, 1). ToCharArray ();        Final char firstchar = strchar[0];        if (Firstchar = = ' {') {            return json_type. Json_type_object;        } else if (Firstchar = = ' [') {            return json_type. Json_type_array;        } else {            return json_type. Json_type_error;        }    }

Determine the JSON string return type Object or array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.