.Net Json解析单引号 [英] .Net Json parse a single quote

查看:74
本文介绍了.Net Json解析单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目的JSON输出如下,其中单引号变为'\ u0027'

 {Jurisdiction Name:Prince George \ u0027s县,医学博士,
最大xxxx:300000}



我想要输出:

< pre lang =HTML>Jurisdiction Name:Prince George's County,MD,



如何在.Net中进行JSON解析?谢谢。

解决方案

在JavaScript中,双引号字符串中的单引号将按原样正确解析。您可以使用以下JavaScript进行检查:

  var  s =   123'456 
var js = JSON .stringify(一个或多个);
s = JSON .parse(js); // 相同,往返后



因此,任何有效的JSON解析器应该是这种情况。



对于解析,请查看我过去的答案:

如何将对象类型转换为C#类对象类型 [ ^ ],

如何将多级json数据转换为C#对象? [ ^ ],

haw从Cloudant(json文档)获取数据 [ ^ ],

解析json字符串数组 [ ^ ]。



-SA

The JSON output of my project is below, where the single quote becomes '\u0027'

{   "Jurisdiction Name": "Prince George\u0027s County, MD",
    "Maximum xxxx": "300000"   }


I want to the output like that:

"Jurisdiction Name": "Prince George's County, MD",


How to do the JSON parse in .Net? Thanks.

解决方案

In JavaScript, a single quote inside double-quoted string will be parsed correctly as it is. You can check it up with the following JavaScript:

var s = "123'456"
var js = JSON.stringify(s);
s = JSON.parse(js); // the same, after the roundtrip


Therefore, it should be the case with any valid JSON parser.

For parsing, please see my past answers:
How To Convert object type to C# class object type[^],
how to conver multi level json data to C# Object?[^],
haw to get data from Cloudant (json document)[^],
deseralize a json string array[^].

—SA


这篇关于.Net Json解析单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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