首页 > Web开发 > 详细

You're trying to decode an invalid JSON String JSON返回有解析问题

时间:2014-11-26 20:33:32      阅读:457      评论:0      收藏:0      [点我收藏+]
SpringMVC架构的web程序,通常用map返回消息在浏览器中显示,但是实际中报下列错误
“”You‘re trying to decode an invalid JSON String“
返回的字符串的被加入了<pre></pre>,

解决方法,在springMvc的配置文件中加入以下配置:

<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean id="jsonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>

同时,在Controller方法体上加入@ResponseBody注解。

另外还有一种解决方法是返回数组形式的消息,如:
resultText = "{success:true,info:‘成功‘}";
 

You're trying to decode an invalid JSON String JSON返回有解析问题

原文:http://www.cnblogs.com/allforone/p/4123971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!