3

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!

0

1 Answer 1

2

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

http://json.codeplex.com/

List<..> result = JsonConvert.DeserializeObject<List<...>>( list );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.