这是给浏览器看的,如果你的json数据中有html标签,那第一种应该不行吧

解决方案 »

  1.   

    好像ie的话返回text/html这样的会把返回结果变成下载东西那样的
    这个你随便开个网页就知道了,返回的contentType搜索下也行
    好像挺多的类型
      

  2.   

    我 一直设置成   response.setContentType("text/html")
    不过 response.setContentType("application/json")这样应该也可以
      

  3.   

    axaj才不管你返回的是什么类型的内容了,有json字符串,他可以解析就行
      

  4.   

    <mvc:resources mapping="/resources/**" location="/resources/" /> <!-- 采用SpringMVC自带的JSON转换工具,支持@ResponseBody注解 -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
    <list>
    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
    </list>
    </property>
    </bean> <!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
    <bean id="mappingJacksonHttpMessageConverter"
    class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
    <property name="supportedMediaTypes">
    <list>
    <value>apolication/json; charset=UTF-8</value>
    <value>text/html;charset=UTF-8</value>
    <value>text/plain;charset=UTF-8</value>
    </list>
    </property>
    </bean>

      

  5.   

    <!-- MVC Annotation Driven -->
    <bean
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
    <list>
    <bean id="utf8StringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
    <property name="supportedMediaTypes">
    <list>
    <value>text/plain;charset=UTF-8</value>
    </list>
    </property>
    </bean>

    <bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
            <!-- 解决 HttpMediaTypeNotAcceptableException: Could not find acceptable representation -->
            <property name="supportedMediaTypes">
                <list>
                    <value>text/html;charset=UTF-8</value>
                </list>
            </property>
         </bean>
        
    </list>
    </property>
    </bean>
      

  6.   

    恩   我也觉得设置成 application/json  比较规范
      

  7.   

    response.setContentType("text/html");
         response.setCharacterEncoding("UTF-8");
      

  8.   

    application/json
    application/text都只是设置返回的http报文里面header的内容,最终怎么处理还是看前端javascript,你js里面收到数据后JSON.parse()就是json数据(当然现在Ajax框架比如jquery都自动parse了),不处理就是纯文本,本质上没什么差别