Spring MVC response results have double quotes

Source: Internet
Author: User

The problem is this:

Using the MVC framework for Spring MVC, when an HTTP request is made, the data return is actually double-quoted, which leads me to convert the data in the foreground. So, what is the specific cause of this? Look at the code below and you'll know!

1) spring-servlet.xml

<!--JSON conversion of the returned JavaBean back to the foreground--><bean name= "Mappingjacksonhttpmessageconverter" class= " Org.springframework.http.converter.json.MappingJacksonHttpMessageConverter "/>

2) Controller.java

@RequestMapping ("/querysubstation") @ResponseBodypublic String get (httpservletrequest request, HttpServletResponse Response) {list<treedto> List = new arraylist<treedto> (); Treedto father = new Treedto () Father.setid ("_001"); Father.settext ("Xiang"); List.add (father); return Jsonarray.fromobject (list). ToString ();}

3) The result of the return is

"[{\" attributes\ ": {},\" checked\ ": False,\" children\ ": [],\" iconcls\ ": \" \ ", \" id\ ": \" _001\ ", \" parent_id\ ": \" \ ", \" State\ ": \" open\ ", \" text\ ": \" Xiang change \ "}]"

4) Problem finding

The problem is that when the data is returned to the client, the JSON format was converted two times, so the problem occurred! It's easy for you to deal with! 1) One way to comment out the Spring-servlet code.

2) One way to return the Java object itself instead of JSON conversion.

Spring MVC response results have double quotes

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.