JSON data parsing

Source: Internet
Author: User
Tags array to string

String str = ' {' person ': ' oneself ', ' info ': {' name ': ' Little King ', ' age ': ' People ': [{' A ': ' Brett ', ' B ': ' McLaughlin ', ' C ': ' AAAA '},{' a ': ' Jason ', ' B ': ' Hunter ', ' C ': ' bbbb '},{' a ': ' Elliotte ', ' B ': ' Harold ', ' C ': ' CCCC '}]} "; Jsonobject Jsonobj=jsonobject.fromobject (str); String Person= jsonobj.getstring ("Person"); System.out.println ("Get character Person:" +Person ); Jsonobject Info= Jsonobj.getjsonobject ("info"); System.out.println ("Get Object Info:(name:" +info.getstring ("name") + "Age:" +info.getstring ("age") + ")"); System.out.println ("Get array People:"); Jsonarray arr= Jsonobj.getjsonarray ("People");  for(inti = 0; I < arr.size (); i++) {jsonobject o=Arr.getjsonobject (i); String a= (String) o.get ("a"); String b= (String) o.get ("B"); String C= (String) o.get ("C"); System.out.println (A+"|" +b+ "|" +c); }        //Ajax request with parameter JSON data//var Jsonarr = new Array (); //var str =json.stringify (Jsonarr); = = "JSON array to string (object same)String gradestring = "[{' A ': ') A1 ', ' B ': ' B1 ', ' C ': ' C1 '},{' a ': ' A2 ', ' B ': ' B2 ', ' C ': ' C2 '},{' a ': ' A3 ', ' B ': ' B3 ', ' C ': ' C3 '}]"; Jsonarray Jsonarr= Jsonarray.fromobject (gradestring);//This is null, or the error will be directlySystem.out.println ("Parse the JSON array from the AJAX request:");  for(inti = 0; I < jsonarr.size (); i++) {jsonobject o=Jsonarr.getjsonobject (i); String a= (String) o.get ("a"); String b= (String) o.get ("B"); String C= (String) o.get ("C"); System.out.println (A+"|" +b+ "|" +c); }

JSON data parsing

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.