问题描述
我遇到了一个问题,我得到了一个带有“"”的旧格式的 json 字符串而不是“\””。当我尝试用“" ;”反序列化时它失败了。所以我手动将其更改为“\””但它仍然失败。这是我的过程:
作为参考,我的 json 看起来像这样:
{
"Contact": {
"ToLine": "me@aol.com","ccline": "you@aol.com"
}
}
string myString = "{"Contact":{"ToLine":"me@aol.com","ccline":"you@aol.com"}}"
然后我使用以下内容将其更改为 json 字符串的外观:
string jsonString = myString.Replace(""","\"");
导致:
string jsonString = "{\"Contact\":{\"ToLine\":\"me@aol.com\",\"ccline\":\"you@aol.com\"}}"
然后当我调用反序列化时:
CustomModel myModel= JsonConvert.DeserializeObject<CustomModel>(jsonString);
但我收到一条错误消息:
Invalid property identifier character: &. Path '',line 1,position 1.
不知道为什么会这样。有谁知道如何用“"”取字符串并将其放入一个对象中?谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)