Convert JSON text to Jsonarray to list<object>

Source: Internet
Author: User

1  PackageCom.beijxing.TestMain;2 3 ImportJava.io.File;4 Importjava.io.IOException;5 Importjava.util.ArrayList;6 Importjava.util.List;7 8 Importorg.apache.commons.io.FileUtils;9 Ten Importcom.beijxing.entity.Student; One  A ImportNet.sf.json.JSONArray; - ImportNet.sf.json.JSONObject; -  the /**  - * Convert JSON text to Jsonarray to list<object> - * @authorAuthor: ywp - * @versioncreated: October 25, 2016 PM 10:30:14 + */ -  Public classTestJson5 { +      Public Static voidMain (string[] args) { A         Try { at Filetojson (); -}Catch(IOException e) { - e.printstacktrace (); -         } -     } -      Public Static voidFiletojson ()throwsioexception{ inFile File =NewFile (TestJson5.class. GetResource ("/jsontext2.json"). GetFile ());//get the file under the project root path -String content =fileutils.readfiletostring (file); to         //Jsonobject jsonobject = jsonobject.fromobject (content); +Jsonarray Jsonarray =jsonarray.fromobject (content); -System.out.println ("Jsonarray:" +Jsonarray); theList<student> lstudents =NewArraylist<student>(); *         //lstudents = jsonarray.tolist (Jsonarray, student.class);//Obsolete Methods $Lstudents = (list<student>) jsonarray.tocollection (Jsonarray, Student.class);Panax NotoginsengSystem.out.println ("Lstudent:" +lstudents); -     } the}

Convert JSON text to Jsonarray to List<object>

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.