Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deserialize json base64 binary in .net using DataContractJsonSerializer

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!

like image 607
Timmerz Avatar asked Dec 14 '25 20:12

Timmerz


1 Answers

I solved the issue by using JSON.NET library instead...worked immediately.

http://json.codeplex.com/

List<..> result = JsonConvert.DeserializeObject<List<...>>( list );
like image 114
Timmerz Avatar answered Dec 17 '25 11:12

Timmerz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!