首先说结论:设置返回String类型的, Response.ContentType = "application/json";等于使用JsonResult。
证据 1:设置返回String类型的, Response.ContentType = "application/json"。JQ会自动把JSON字符串转换为JSON对象。
如果不设置 Response.ContentType = "application/json",则是使用默认值Response.ContentType = "text/html"。这样JQ就不会把JSON字符串转换为JSON对象。
看如下两个实例:
---------------------------------------------------------------

-----------------

-----------------

------------------------------------------------------------------------
------------------------------------------------------------------------



证据 2:设置JsonResult 的ContentType = "text/html",这样JQ就不会把JSON字符串转换为JSON对象。
反之,使用默认值就是ContentType = "application/json ",JQ会自动把JSON字符串转换为JSON对象。
看如下两个实例:
----------------------------------------------------------------------

---------------------------

--------------------------

----------------------------------------------------------------------------
----------------------------------------------------------------------------

-----------------------------------------------------------

-------------------------------------------------------------

----------------------------------------------------------------------------
如上证据证明了,我的结论。
如下在记几点:
1.当返回到前端的json数据,不标准时如--"{"Age":"fdasfdasf","name":"rer"}",前端抓包的值和我给的一样。不管你是用
JsonResult和返回String类型,都需要手动, JSON.parse(Data),才能把字符串变为JSON对象。
1.当返回到前端的json数据,标准时如--"{"Age":"fdasfdasf","name":"rer"}",前端抓包的值和我给的一样。
只需要保证响应报文头的ContentType = "application/json,JQ 都会自动把JSON字符串转换为JSON对象。
2014.09.02 六欲 在广州