嘿,我在使用wcf datacontract将base64 json反序列化回.net对象时遇到了问题....
我有这个反序列化:
public static T FromJSON<T>( this string json )
{
using ( MemoryStream ms = new MemoryStream(ASCIIEncoding.Default.GetBytes(json)) )
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
return (T)ser.ReadObject(ms);
}
}
和......我的模特课中有这个...
[DataMember]
[Column(AutoSync = AutoSync.Always, DbType = "rowversion not null", CanBeNull = false, IsDbGenerated = true, IsVersion = true, UpdateCheck = UpdateCheck.Never)]
public byte[] timestamp { get; set; }
和...我正在把json传回去......
[{"id":"1","type":"H","date_issued":"\/Date(1286856000000)\/","date_ceu":"\/Date(1603166400000)\/","current":true,"timestamp":"AAAAAAAAD7M="}]
由于某种原因,它只是拒绝简单地将base64放回byte [] ......必须有其他方法让它工作......
另外,我正在使用ASP.NET MVC和Html.Hidden(...)将二进制序列化为base64以开始....
谢谢!
答案 0 :(得分:2)
我通过使用JSON.NET库解决了这个问题......立即工作。
List<..> result = JsonConvert.DeserializeObject<List<...>>( list );