如何在Scala中将List转换为Json数组

时间:2013-09-13 06:11:29

标签: json list scala arrays

这是我的代码,这里返回类型是列表,但列表转换为数组,返回类型更改为字符串

    @RequestMapping(value =Array( "/StandardChange.html"))
    @ResponseBody
    def  findDivisionOfStandards(@RequestParam  divisionid:Long):List[Division] ={

     var division:List[Division]= null
     if (divisionid != null) {

        division  = divisionService.findDivisionByStandardId(divisionid)            
    }       
     division  
    }

我试过了,但这不起作用

返回类型更改列表更改为字符串,值更改为列表更改为 Json数组

  @RequestMapping(value =Array( "/StandardChange.html"))
  @ResponseBody
    def  findDivisionOfStandards(@RequestParam  divisionid:Long):String ={

      var division:List[Division]= null

      if (divisionid != null) {

           division  = divisionService.findDivisionByStandardId(divisionid)         

        }   
       var divisionjsonArray=  division.toArray     **json convert should be here**

      divisionjsonArray
    }

1 个答案:

答案 0 :(得分:2)

compact(render(decompose(division)))