C# JSON.NET无法反序列化看似有效的JSON Blob

C# JSON.NET无法反序列化看似有效的JSON Blob,c#,.net,json,serialization,json.net,C#,.net,Json,Serialization,Json.net,我有一个JSON blob,我从一个服务返回,随后将其转换为字符串 然后,如果我为字符串存储在变量中的位置设置断点,我可以在Visual Studio JSON可视化工具中轻松查看该字符串: 值得一提的是,JSON数据包含大量转义字符,这些字符再次在JSON可视化工具中正确呈现 我得到的JSON blob遵循以下模式: [ { "property" : "Value", "property2" : "Value\\ of the string." }, {

我有一个JSON blob,我从一个服务返回,随后将其转换为字符串

然后,如果我为字符串存储在变量中的位置设置断点,我可以在Visual Studio JSON可视化工具中轻松查看该字符串:

值得一提的是,JSON数据包含大量转义字符,这些字符再次在JSON可视化工具中正确呈现

我得到的JSON blob遵循以下模式:

[
   {
     "property" : "Value",
     "property2" : "Value\\ of the string."
   },
   {
     "property" : "ValueX",
     "property2" : "ValueY\\ of the string."
   }
]
当我启动反序列化过程时,使用以下代码:

JsonSerializerSettings settings = new JsonSerializerSettings();

settings.NullValueHandling = NullValueHandling.Include;
settings.StringEscapeHandling = StringEscapeHandling.Default;

List<Station> deserializedYaps = JsonConvert.DeserializeObject<List<Station>>(data, settings);
JsonSerializerSettings设置=新建JsonSerializerSettings();
settings.NullValueHandling=NullValueHandling.Include;
settings.StringEscapeHandling=StringEscapeHandling.Default;
List deserializedYaps=JsonConvert.DeserializeObject(数据、设置);
我得到以下错误:

将值转换为类型时出错 'System.Collections.Generic.List'1[Beem.StationModels.Station]'。路径 '',第1行,位置29904

其中29904是从服务获取的JSON字符串中的最后一个字符

Station
类提供了正确的JSON属性绑定,并具有默认构造函数


我在这里遗漏了什么?

Newtonsoft Json 4.0.5.0做得很好,假设station类如下所示:

    public class Station
    {
        public object Property { get; set; }
        public object Property2 { get; set; }
    }
您可以这样进行测试:

        sb.AppendLine("[");
        sb.AppendLine("   {");
        sb.AppendLine("     \"property\" : \"Value\",");
        sb.AppendLine("     \"property2\" : \"Value\\\\ of the string.\"");
        sb.AppendLine("   },");
        sb.AppendLine("   {");
        sb.AppendLine("     \"property\" : \"ValueX\",");
        sb.AppendLine("     \"property2\" : \"ValueY\\\\ of the string.\"");
        sb.AppendLine("   }");
        sb.AppendLine("]");

        var json = sb.ToString();

        var settings = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Include};                        

        var deserializedYaps = JsonConvert.DeserializeObject<List<Station>>(json, settings);
sb.AppendLine(“[”);
某人附加物(“{”);
sb.附录行(“\”属性\“:\”值\“,”);
sb.AppendLine(“\”property2\”:\”字符串的值\\\”;
某人附言(“}”);
某人附加物(“{”);
sb.附录行(“\”属性\“:\”值\“,”);
sb.AppendLine(“\'property2\”:\'ValueY\\\\\of the string.\”);
(b)附加物(“}”);
某人以“]”号结尾;
var json=sb.ToString();
var settings=newjsonserializersettings{NullValueHandling=NullValueHandling.Include};
var deserializedYaps=JsonConvert.DeserializeObject(json,设置);

JSON通过了吗?我成功地反序列化了您的JSON。您确定字符串确实有两个反斜杠,如:
“字符串的值\\。”
?或者字符串只有一个反斜杠,Visual Studio在显示时会“有用地”转义它,例如:
“字符串的值”。
?能否显示
类?上面的JSON是一个测试块,不是实际的JSON。这个字符串实际上有两个反斜杠,它通过了JSONLint。想象一下同样的一桶数据,但重复了60次。出于某种原因,它只是不想处理数据,即使是作为一个
JArray
。另外,是的,我的
Station
类遵循与上述相同的模式。