在 .NET Core 中处理 JSON 字符串中出现的 ''' 字符,可以使用转义字符 ''' 来表示双引号。

例如,如果要将一个包含双引号的字符串转换为 JSON 字符串,可以使用以下代码:

string value = 'This is a 'quoted' string';
string jsonValue = JsonSerializer.Serialize(value);

Console.WriteLine(jsonValue);

输出结果为:'This is a \'quoted\' string'

在反序列化 JSON 字符串时,.NET Core 会自动处理转义字符,将其还原为原始的双引号字符。

string jsonValue = '\'This is a \\\'quoted\\\' string\'';
string value = JsonSerializer.Deserialize<string>(jsonValue);

Console.WriteLine(value);

输出结果为:This is a 'quoted' string

在 .NET Core 中处理 JSON 字符串中的双引号

原文地址: https://www.cveoy.top/t/topic/qnxT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录