Spring MVC returns JSON format and JSON string

Source: Internet
Author: User

First it is necessary to say that JSON and JSON strings are not the same, the latter is a string. And JSON is an object

Of course, if the call location is a daemon this is almost indistinguishable, because in the background, regardless of the format data, the string is read from the response stream.

But there's a big difference in the front end.

Yes, it's a string,

This taxs is saved in the previous step.

Looking at another request

This is the JSON object.

These two forms, in fact, a difference is in the return of the header information in the Content-type

If Content-type is Application/json, the browser automatically converts to a JSON object after receiving the object, and if it is text/html, it is passed to the callback function as a string

Three ways to return objects in JSON form in the background here is not much to say, is two configurations and a @responsebody

If this sentence is configured in Spring-mvc.xml (which is not necessarily the name of this file), the JSON object is returned, otherwise the JSON string is returned.

The personal guess is that in this configuration file there should be an interceptor that modifies the default Content-type

<mvc:annotation-driven content-negotiation-manager= "Contentnegotiationmanager"/>

Spring MVC returns JSON format and JSON string

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.