Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.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# 使用Json.Net处理数据中的换行符_C#_Asp.net Web Api_Newline_Json.net - Fatal编程技术网

C# 使用Json.Net处理数据中的换行符

C# 使用Json.Net处理数据中的换行符,c#,asp.net-web-api,newline,json.net,C#,Asp.net Web Api,Newline,Json.net,在JSON.NET中有没有处理换行符的方法。我有一些数据返回,其中包含回车换行符,Json.Net只是在返回值中保留原始数据。有没有办法强制Json.Net将其编码为Json。我以为这会在默认情况下发生,但对我来说不是这样。也许我错过了别的东西 如果有必要的话,我正在MVC4WebAPI项目中使用Json.Net 返回我的数据时,字符串中包含\r\n,如 "Keywords": "These are my keywords.\r\n\r\n\r\nThis is a second line.

在JSON.NET中有没有处理换行符的方法。我有一些数据返回,其中包含回车换行符,Json.Net只是在返回值中保留原始数据。有没有办法强制Json.Net将其编码为Json。我以为这会在默认情况下发生,但对我来说不是这样。也许我错过了别的东西

如果有必要的话,我正在MVC4WebAPI项目中使用Json.Net

返回我的数据时,字符串中包含\r\n,如

  "Keywords": "These are my keywords.\r\n\r\n\r\nThis is a second line...\r\n\r\nThis is a third line. ...\r\n\r\n\r\nThis is a 4th line ..."
据我所知,应该是这样
\\r\\n
。我返回的数据可能有问题,但我只是想看看JSON.NET应该如何处理这些数据

可以使用选项Formatting.Indented序列化对象。 像这样:

string yourJsonString = JsonConvert.SerializeObject(yourObject,  Formatting.Indented, new JsonSerializerSettings { });
我认为这应该行得通


问候。

您的输入如何?您希望得到什么样的输出?您能否详细说明“将此编码为json”的含义?JSON规范要求数据返回时包含CRLF,这是完全符合犹太教的。你知道这一点吗?