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

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>
           <value>application/json</value>

</list>
</property>
</bean>
</list>
</property>
</bean>

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

另外还有一种解决方法是返回数组形式的消息,如:
resultText = "{success:true,info:'成功'}";
 
posted @ 2014-11-26 18:08  all_forone  阅读(4271)  评论(0编辑  收藏  举报