我使用Json.Net(Newtonsoft)将数据反序列化为对象。我从另一个我无法控制的源代码中获取JSON文件,并且值中包含逗号,如下所示:
"Hello, World"
它有双引号。当它被反序列化为对象时,它会在逗号上拆分并将Hello放入一个字段值,将World放入下一个字段值。
是否有修复此问题的序列化程序设置(JsonSerializerSettings)?我找不到任何明显的东西。
编辑:对不起延迟 - 我被另一个项目搞砸了然后不得不做CES ......这是我用过的代码:
Dim P As JSONProduct = New JSONProduct
Dim S As JsonSerializerSettings = New JsonSerializerSettings
Dim data As String = IO.File.ReadAllText("B:\Downloads\JSON\file.json")
Try
P = JsonConvert.DeserializeObject(data, GetType(JSONProduct), S)
Catch exjr As JsonReaderException
MsgBox("Reader Exception: " & exjr.Message)
Catch exjs As JsonSerializationException
MsgBox("Serialization Exception: " & exjs.Message)
Catch exj As JsonException
MsgBox("JSON Exception: " & exj.Message)
End Try
答案 0 :(得分:0)
我切换到JavaScriptSerializer(System.Web.Script.Serialization),问题就消失了。太糟糕了,我喜欢Newtonsoft的东西。