How to resolve .net core 3.1 json deserialization exception.

kishore kumar 1 Reputation point
2021-07-28T08:56:08.107+00:00

Dear Experts,

Please help me to resolve this below exception.

I am using .net core 3.1 System.Text.Json namespace, I don't want to use third party components.

string jsonStr= "{  \"name1\": \"test\",  \"key\": \"test2\",  \"args\": {    \"value\": \"%PDF-1.4 Scanned ImagePDF%Non-Encryption3 0 obj<</Type /Page/Parent 1 0 R/Resources 4 0 R/Contents 5 0 R/MediaBox [0 0 613 790]>>endobj4 0 obj<</ProcSet [/PDF /ImageB]/XObject << /Img1 6 0 R >>>>endobj5 0 obj<</Length 27>>stream613 0 0 790 0 0 cm/Img1 Doendstreamendobj6 0 obj<</Type /XObject/Subtype /Image/Name /Img1/Filter /CCITTFaxDecode/DecodeParms <<  /K -1 /Columns 1704 /Rows 2196 >>/Width 1704/Height 2196/BitsPerComponent 1/ColorSpace /DeviceGray/Length 7 0 R>>stream_�������W]������}�Y���������W��_����������)�����������������������������������������!|�P!E�;!a̝��0�fC@@ h`�gNKb���@����<&�M�au�D<�;D??KDB:D\"*��?�oA�A����}&�6�;�zo����:o����+�'�m'���������W�Q��C#G���*�`C�xDX��PEx����N�F�Π�0\\�j ���=<q[c��\\ xA��a��M�m��\t��/�^�ڽ�A���Z!0������8\"?������Bg���P�`�?�^\"a�o�,6�> ����� l�PA�&��`�A�>�a�?�uG���_���a{ @0�I��dŲ�����I��؞��'݃I�>�u���{�����ޟ����5��a�������0��^���L������=��YIA����8�Z ���\"  }}";
    var data = JsonSerializer.Deserialize<Dictionary<string, object>>(jsonStr);

The above code not able to desterilize to an Dictionary<string, object> type.
Here in the json string value key contains the pdf file data, it may have some unprintable characters also.

Can you please help us to resolve deserilize to a dictionary.

Best Regards,
Kumar

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,962 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.