Convert list data form to JSON form

Source: Internet
Author: User

Action

 Public String showallexperts () {       try  {        list=  Rescueexpertsservice.findrescueexpertslist ();           springcontextassist. Getbean (ijsongenerator.class);//Get to transfer mechanism         = json.getjsonstring (list); //Convert list to JSON
Catch (Exception e) {


return "Rescue_experts_mapview"
}
Springcontextassist
 PackageCom.hfky.crs.busi.service;Importorg.springframework.beans.BeansException;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.ApplicationContextAware;ImportOrg.springframework.stereotype.Service; @Service Public classSpringcontextassistImplementsApplicationcontextaware {Private StaticApplicationContext context; @Override Public voidSetapplicationcontext (ApplicationContext ApplicationContext)throwsbeansexception {Context=ApplicationContext; }           Public Static<T> T Getbean (String beanname,class<t>CLS) {          returnCls.cast (Context.getbean (beanname)); }           Public Static<T> T Getbean (class<t>type) {        returnContext.getbean (type); }} 
Ijsongenerator.class
 PackageCom.hfky.crs.busi.service;Importjava.util.List;ImportCom.google.gson.ExclusionStrategy; Public InterfaceIjsongenerator { Publicijsongenerator Applydateformat (String pattern); /*** Convert an object instance to a JSON string *@paramtarget object to convert *@returnJSON string*/     PublicString getjsonstring (Object target); /*** Get JSON String *@paramTarget *@parames *@return     */     PublicString getjsonstring (Object target,exclusionstrategy es); /**     *      * @paramTarget *@paramexcluded *@return     */     PublicString getjsonstring (Object target,class<?>... excluded); /*** Get object instances from JSON String *@param<Type> Result class type *@paramJSON JSON String *@paramCLS Type *@returntarget Object*/     Public<Type> Type getjsonobject (String json,class<type>CLS); /**     * @param<Type> *@paramJSON *@paramCLS *@return     */     Public<Type> list<type> Getlistfromjson (String json,class<type>CLS); }

Convert list data form to JSON form

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.