Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我可以在ASP.Net项目的代码隐藏中使用JSON.Stringify吗?_C#_Asp.net_Json - Fatal编程技术网

C# 我可以在ASP.Net项目的代码隐藏中使用JSON.Stringify吗?

C# 我可以在ASP.Net项目的代码隐藏中使用JSON.Stringify吗?,c#,asp.net,json,C#,Asp.net,Json,在ASP.NET项目(MVP模式)的代码隐藏中,我在一个演示者中得到一个字符串,其中包含类似于JSON文件内容的内容 然后,我使用该字符串设置视图的一个属性(分配给演示者) 在视图中,字符串显示在一个文本框中,但它看起来不太好,因为它不是用换行符和换行符构成的。 我知道有一个名为Stringify的JSON函数可以使这些字符串变得漂亮 我可以在代码隐藏中调用JSON函数吗? 在演示者中设置视图属性时的每个示例 所以我在演示者中设置了它: this.view.ContentAsJson = Get

在ASP.NET项目(MVP模式)的代码隐藏中,我在一个演示者中得到一个字符串,其中包含类似于JSON文件内容的内容

然后,我使用该字符串设置视图的一个属性(分配给演示者)

在视图中,字符串显示在一个文本框中,但它看起来不太好,因为它不是用换行符和换行符构成的。 我知道有一个名为Stringify的JSON函数可以使这些字符串变得漂亮

我可以在代码隐藏中调用JSON函数吗? 在演示者中设置视图属性时的每个示例

所以我在演示者中设置了它:

this.view.ContentAsJson = GetContentAsJson(uuid);
这就是我想做的,如果可能的话:

this.view.ContentAsJson = JSON.Stringify(GetContentAsJson(uuid));
GetContentAsJson
是一个创建并返回JSON字符串的函数

我的看法是:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentJsonView.ascx.cs" Inherits="WebCenter.PP.PI.WebGui.View.FolderView.ContentJsonView" %>
<%@ Import Namespace="WebCenter.PP.Common.Domain" %>
<div id="DivContentJson" class="clearfix">
    <p>
        <asp:TextBox runat="server" ID="TbContentJson" TextMode="MultiLine" Height="100%" Width="100%" />
    </p>
</div>
JSON.stringify()
实际上将JavaScript对象转换为字符串,您可以在服务器端这样做:

using System.Web.Script.Serialization;

var json = new JavaScriptSerializer().Serialize(obj);

编辑:
JSON.stringify()
是客户端(浏览器)功能。因此,您不能在服务器端执行此操作。

您可以使用

JsonConvert.SerializeObject(ob)

从library:Newtonsoft.Json

只需发布一段您尝试过的内容?可能与的重复好的,我编辑了我的解释并添加了我项目中的一些示例。GetContentAsJson(uuid)返回什么?不,它只是获取数据的字符串变量。该数据用于创建JSON的内容。
JsonConvert.SerializeObject(ob)