1

I want to deserialize blob into custom object.

From blob I get byte[], convert into string and then, using JSON.Net deserialize into object.

public object FromByteArray(Type type, byte[] value)
{
    return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(value), type);
}

But sometimes there are blobs with special symbols in one of properties.

"LogoUrl":"�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u00002\u0000\u0000\u00002\b\u0003\u0000\u0000\u0000)�x�\u0000\u0000\u0001,PLTE������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������8�\u0000\u0000\u0001�IDATx^�e��0\u0010��i\u000b�����������%ò�!o�����>\t�ӜC��R�8\"R��I>2;5���+����\u0012=�(\u0010�ݱ�EDi\u0012C��׫\u0003����(\u001a�\u001a��_)\"�vTZ)���z`d\n��\u0010�qO�8�`\\&��ao�U��s\u0012�d\f�0�\u0018�\ty��(L�(���͞\u001c�\u0006[X���1*>a85�\u001d��T�u\u0000��n���0�F�����!xTZT\rU��\t���5��jxM�,�$\u001aۨ���\u0016U�%�*����\u0015�\u0000��7T\u0014�Y\u001a��\u000e���a�\u001c��)�oGB���\u0019ξ�(�c4|&�%�V��g\t��\u0004�4]�\f6ض��\"Fp!jYt�$d�?�ȥ9�pIi�Gh�aE[��;0����Q,C�?\u0003~\u000b,��,��?�J���M[��Nm\u0011�Ky\f��h�c�=D�D%\u0002���>��\"\tow!\u0004S���?��\u0006rI\u0003\u0011n��J�T��#����D�@\u0001��+�' �L\u0012F\u0003\u0004\tA�\u0007r�\bw&cm�\u0001�b\u001f��qi\u0000\u0000\u0000\u0000IEND�B`�"

It cannot be deserialized by default as I understand. I tried to add JsonSerializerSettings with option StringEscapeHandling.EscapeNonAscii but this doesn't help to solve this issue.

Is there any other way to resolve it?

Tried also deserialize string for 2nd time, this helps to get an object, but not seems like it is the correct way.

demo
  • 6,038
  • 19
  • 75
  • 149
  • look the link https://stackoverflow.com/questions/1443158/binary-data-in-json-string-something-better-than-base64 – Lance Sep 30 '19 at 10:10
  • We need to see how the JSON was serialized, or at the minimum, the raw contents of the `byte []` array, to help you. – dbc Oct 01 '19 at 17:55

1 Answers1

0

change your Encoding type from UTF8 to Default

public object FromByteArray(Type type, byte[] value)
{
    return JsonConvert.DeserializeObject(Encoding.Default.GetString(value), type);
}
senthilkumar2185
  • 2,536
  • 3
  • 22
  • 36