Conversion of list and JSON arrays (source code)

Source: Internet
Author: User

 Public classa11111111 {//The parameter obj can be a JSON object, a string, a list     Public  Static voidFun (Object obj) {jsonarray data=jsonarray.fromobject (obj);             for(intI=0; I<data.size (); i++) {Jsonobject jobj= (jsonobject) data.Get(i); System. out. println (Jobj); /** *{"aid": 3201, "name": "Brand", "CID": "1351"} {"Aid": 7716, "name": "Type", "CID": "1351"} {"Aid": 8668, "name": "Price", "CID": "1351"}*/String name= (String) jobj.Get("name"); System. out. println (name);//Brand Type Price         }       }               Public Static voidMain (string[] args) {
Making a string
    //String list = Request.getparameter ("json");String STR9 ="[{\ "aid\": 3201,\ "name\": \ "brand \", \ "cid\": \ "1351\"}, {\ "aid\": 7716,\ "name\": \ "type \", \ "cid\": \ "1351\"}, {\ "aid\" : 8668,\ "name\": \ "price \", \ "cid\": \ "1351\"}]" ; Fun (STR9); //Make a listList<object> list90 =NewArraylist<object>(); Jsonarray Data=Jsonarray.fromobject (STR9); for(intI=0; I<data.size (); i++) {Jsonobject jobj= (jsonobject) data.Get(i); List90.add (Jobj); //turn a JSON array into a list /** *{"aid": 3201, "name": "Brand", "CID": "1351"} {"Aid": 7716, "name": "Type", "CID": "1351"} {"Aid": 8668, "name": "Price", "CID": "1351"}*/} fun (LIST90); //The 2 functions that are called are the same as the resultsString str_0=list90.tostring (); Fun (STR_0); //The results are all the same. } }

Conversion of list and JSON arrays (source code)

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: 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.