This seems so simple I must be over-thinking it.

TL;DR;

如何修改下面的代码以返回字符串中包含的json对象,而不是恰好包含json的字符串?

public ActionResult Test()
{
  var json_string = "{ success: \"true\" }";
  return Json(json_string, JsonRequestBehavior.AllowGet);
}

This code returns a string literal containing the json:

"{ success: "true" }"

但是,我希望它返回字符串中包含的json:

{ success: "true" }

Slightly longer version

I'm trying to quickly prototype some external api calls and just want to pass those results through my "api" as a fake response for now. The json object is non-trivial - something on the order of 10,000 "lines" or 90KB. I don't want to make a strongly typed object(s) for all the contents of this one json response just so I can run it through a deserializer - so that is out.

所以我的控制器的基本逻辑是:

  1. 调用外部所有接口
  2. Store string result of web request into a var (see json_string above)
  3. Output those results as json (not a string) using the JsonResult producing method Json()

Any help is greatly appreciated... mind is melting.

推荐答案

Json() helper方法的全部要点是序列化为JSON.

If you want to return raw content, do that directly:

return Content(jsonString, "application/json");

Json相关问答推荐

PowerShell脚本-替换json数组(转义$var将被视为不带双引号的文本)

Jolt将键和值转换为单独的数组集

对面的行/列进行排序时可能出现错误

如何用JQ更改空/布尔/数字的 colored颜色 ?

如何让JSON子查询在没有行的情况下返回空数组而不是NULL

错误解析错误:意外令牌:在我的 .eslintrc.json 文件中.为什么?

如何编写 jolt 规范以将不同的对象转换为数组

如何使用 jq 在连续的 json 记录流上调用操作

嵌套存储在字符串变量中的 JSON 对象

用powershell条件解析json文件的数组对象

将哈希表转换为 json 后,Powershell 缺少数组

应该使用什么标头将 GZIP 压缩 JSON 从 Android 客户端发送到服务器?

Python Flask-Restful POST 不采用 JSON 参数

如何从 mysql 数据库构建 JSON 数组

谷歌浏览器不允许我放置断点

验证和格式化 JSON 文件

使用 ajax 将 JSON 发送到 PHP

使用 Node.js 对 JSON 中的字符串大小有限制吗?

在android中读取Json数组

杰克逊自动将 Joda DateTime 格式化为 ISO 8601 格式