0

I have a class

[Serializable]
public class DocumentMetadataBEO
{
    public Guid ItemId { get; private set; }
    public byte[] HashValue { get; set; }
}

I am receiving string having both of the above value.

However when i try to deserialize as below -

documentMetadata = JsonConvert.DeserializeObject<DocumentMetadataBEO>(responseFromServer);

HashValue property is getting set null. How can I deserialize it?

Here is the Json format, we get from server

"{
    \"ItemId\":\"a1606584-9b9e-4bba-845f-e775eb5ebda5",   
    \"HashValue\":\"UHj5WO00uD5MIeCEr0Bt8i03iMrqUfILky7wSiqIn7g=\
"}"
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
Rahul K
  • 17
  • 1
  • 9
  • 3
    how does your string look like in `responseFromServer` ? – Mong Zhu May 17 '17 at 15:39
  • 2
    Please post an example of the JSON (serialized value) you are attempting to deserialize. – John M. Wright May 17 '17 at 15:40
  • Here is the Json we get from server "{\"ItemId\":\"a1606584-9b9e-4bba-845f-e775eb5ebda5\",\"HashValue\":\"UHj5WO00uD5MIeCEr0Bt8i03iMrqUfILky7wSiqIn7g=\"}" – Rahul K May 17 '17 at 15:42
  • please use the [edit](http://stackoverflow.com/posts/44029287/edit) button below your post, to add this information into your question. – Mong Zhu May 17 '17 at 15:43
  • 2
    Look up how to decode from Base64 encoded string. You are going to need two steps here. Deserialize the hash to a string, then base64 decode the string to byte[] – Crowcoder May 17 '17 at 15:43
  • He doesn't need 2 steps. he can create a custom converter like this http://stackoverflow.com/questions/15510742/newtonsoft-json-deserializing-base64-image-fails – Fran May 17 '17 at 15:50
  • @Fran, I try to consider the experience level of the OP. I assume if OP does not recognize base64 encoding that a custom converter might be overwhelming. But, yes, agreed a converter may be in order. – Crowcoder May 17 '17 at 15:58

1 Answers1

1

With a newer version of Json.NET, it is working out of the box. screenshot

Artyom
  • 1,065
  • 8
  • 12