Java parsing JSON data

Source: Internet
Author: User

JSON data is generally divided into two types, object and array.

JSON parsing requires write exception handling.

The JSON object is parsed using the Jsonobject class, such as

     Public voidAnalys_jsonobject (String jsondata) {//Jsondata is the JSON data in the object format        Try{jsonobject Jsonobject=NewJsonobject (Jsondata); String one_string= Jsonobject.getstring ("Key value name");//get a string by key-value nameJsonobject one_jsonobject = Jsonobject.getjsonobject ("Key value name");//get the JSON object in object format by key value nameJsonarray One_jsonarray = Jsonobject.getjsonarray ("Key value name");//get array-formatted JSON objects with key-value names}Catch(Exception e) {e.printstacktrace (); }    }

The Jsonarray class uses similar:

     Public voidAnalys_jsonarray (String jsondata) {//Jsondata is the JSON data in the array format        Try{Jsonarray Jsonarray=NewJsonarray (Jsondata); String One_json= jsonarray.getstring (0);//extracting data by int type numbersJsonobject one_jsonobject = jsonarray.getjsonobject (0);//Get Object-formatted JSON objects with int numbersJsonarray One_jsonarray = jsonarray.getjsonarray (0);//get array-formatted JSON objects with int numbers}Catch(Exception e) {e.printstacktrace (); }    }

Java parsing JSON data

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.