JSON-generated JSON string

Source: Internet
Author: User

Generates a JSON-formatted string.

Need related packages

1  PackageCn.itcast.controller;2 3 Import Staticorg.junit.assert.*;4 5 Importjava.util.ArrayList;6 Importjava.util.List;7 8 ImportNet.sf.json.JSONArray;9 ImportNet.sf.json.JSONObject;Ten ImportNet.sf.json.JsonConfig; One  A Importorg.junit.Test; -  - Importcn.itcast.domain.Province; the  -  Public classJsonlibtest { -  - @Test +      Public voidtest1 () { -Province p =NewProvince ("Shandong province", "250000"); +Jsonobject jsonobj =Jsonobject.fromobject (p); A System.out.println (jsonobj.tostring ()); at     } - @Test -      Public voidtest2 () { -list<province> PS =NewArraylist<province>(); -Ps.add (NewProvince ("Anhui province", "001")); -Ps.add (NewProvince ("Zhejiang province", "002")); inPs.add (NewProvince ("Jiangsu province", "003")); -Jsonarray Jsonarr =Jsonarray.fromobject (PS); to System.out.println (jsonarr.tostring ()); +     } - @Test the      Public voidtest3 () { *list<province> PS =NewArraylist<province>(); $Ps.add (NewProvince ("Anhui province", "001"));Panax NotoginsengPs.add (NewProvince ("Zhejiang province", "002")); -Ps.add (NewProvince ("Jiangsu province", "003")); the          +Jsonconfig cfg =NewJsonconfig ();//JSON string Filtering ACfg.setexcludes (Newstring[]{"ZipCode"});//list of fields not included the          +Jsonarray Jsonarr =Jsonarray.fromobject (ps,cfg); - System.out.println (jsonarr.tostring ()); $     } $}

In the JSP page

1                     2                     var data=this. responsetext; 3                     4                     var provincejson=eval ("(" +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.