我有一些像这样的json数据:
{
'vehicles':{
...
},
'arenaUniqueID':214197923159382012L,
'common':{
...
},
'players':{
...
},
'personal':{
...
}
}
和反序列化此数据的类
public class UnPickledData
{
public Dictionary<int, Vehicle> vehicles { get; set; }
public long arenaUniqueID { get; set; }
public Common common { get; set; }
public Dictionary<int, Player> players { get; set; }
public Personal personal { get; set; }
}
反序列化程序中的抛出异常:
解析值后,遇到意外字符:L。Path arenaUniqueID&#39;,第1行,第51810位。
我试图为该属性编写自己的自定义JSonConverter: 改变了班级:
public class UnPickledData
{
public Dictionary<int, Vehicle> vehicles { get; set; }
[JsonConverter(typeof(CustomLongConverter))]
public Int64 arenaUniqueID { get; set; }
public Common common { get; set; }
public Dictionary<int, Player> players { get; set; }
public Personal personal { get; set; }
}
转换器代码:
class CustomLongConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(long);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Int64.Parse(reader.Value.ToString());
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotSupportedException();
}
}
但是这个例外仍然存在。
我做错了什么以及如何解决这个问题?
P.S。使用Newtonsoft.JSON v5.0.5.16108 / .Net FW 3.5 / VS 2010
答案 0 :(得分:3)
数字后的L无效JSON。