JSON结果包裹在pre标签 - 如何获得它的价值 [英] Json result wrapped in pre tag - how to get value of it

查看:345
本文介绍了JSON结果包裹在pre标签 - 如何获得它的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用JSON工作。我想从我的操作方法返回JSON:

 公共JsonResult上传()
{
   ...
   返回JSON(新{富=SOS .... SOS .... SOS ......});
}

但结果我得到的是在这个pre的标签我的信息包。如何从这个解析富?

 < pre风格=自动换行:打破字;空格:pre-包装;> {foo的:SOS .... SOS .... SOS ......}< / pre>中


解决方案

我想您收到包裹在pre标签中的数据的原因是因为您所请求的数据作为HTML而不是纯文本或JSON。

尝试指定的数据类型为JSON停止响应转换为HTML。

This is first time that I work with json. I am trying to return Json from my action method:

public JsonResult Upload()
{
   ...
   return Json(new { foo = "sos....sos....sos..."});
}

But in result all I get is my message wrap in this "pre" tag. How to parse "foo" from this?

"<pre style="word-wrap: break-word; white-space: pre-wrap;">{"foo":"sos....sos....sos..."}</pre>"

解决方案

I think the reason you are receiving the data wrapped in a pre tag is because you are requesting the data as HTML and not plain text or json.

Try specifying the data type as json to stop the response being converted to HTML.

这篇关于JSON结果包裹在pre标签 - 如何获得它的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆