JSON序列化的base64二进制使用DataContractJsonSerializer .NET [英] deserialize json base64 binary in .net using DataContractJsonSerializer
问题描述
我有使用WCF datacontract反序列化的base64 JSON回.NET对象的问题....
我有这样的反序列化:
公共静态牛逼FromJSON< T>(此字符串JSON)
{
使用(MemoryStream的毫秒=新的MemoryStream(ASCIIEncoding.Default.GetBytes(JSON)))
{
DataContractJsonSerializer SER =新DataContractJsonSerializer(typeof运算(T)); 回报(T)ser.ReadObject(MS);
}
}
和...我有这个在我的模型类...
[数据成员]
[列(自动同步= AutoSync.Always,的DbType =rowversion非空,CanBeNull =假,IsDbGenerated = TRUE,IsVersion = TRUE,UpdateCheck的= UpdateCheck.Never)
公共字节[] {时间戳获得;组; }
和... ...我传递回JSON像这样...
<$p$p><$c$c>[{\"id\":\"1\",\"type\":\"H\",\"date_issued\":\"\\/Date(1286856000000)\\/\",\"date_ceu\":\"\\/Date(1603166400000)\\/\",\"current\":true,\"timestamp\":\"AAAAAAAAD7M=\"}]和出于某种原因,它只是拒绝简单地说是的base64回的byte [] ...必须有一些其他的方式来得到它的工作...
另外,仅供参考我使用ASP.NET MVC和Html.Hidden(...)的串行二进制进的base64开始与....
谢谢!
我用JSON.NET库,而不是解决问题......马上工作。
清单&LT; ..>结果= JsonConvert.DeserializeObject&LT;名单,LT; ... >>(清单);
Hey, I am having a problem deserializing base64 json back into the .net object using wcf datacontract....
I have this to deserialize:
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);
}
}
and...I have this in my model class...
[DataMember]
[Column(AutoSync = AutoSync.Always, DbType = "rowversion not null", CanBeNull = false, IsDbGenerated = true, IsVersion = true, UpdateCheck = UpdateCheck.Never)]
public byte[] timestamp { get; set; }
and...I'm passing the json back like so...
[{"id":"1","type":"H","date_issued":"\/Date(1286856000000)\/","date_ceu":"\/Date(1603166400000)\/","current":true,"timestamp":"AAAAAAAAD7M="}]
and for some reason it just refuses to simply put that base64 back into the byte[]...there must be some other way to get it to work...
also, fyi I'm using ASP.NET MVC and Html.Hidden(...) which serializes the binary into base64 to begin with....
thanks!
I solved the issue by using JSON.NET library instead...worked immediately.
List<..> result = JsonConvert.DeserializeObject<List<...>>( list );
这篇关于JSON序列化的base64二进制使用DataContractJsonSerializer .NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!