C # When deserializing A json string, the prompt is: the element "root" from the namespace ".. If the namespace is "" or "None ".,

Source: Internet
Author: User

C # When deserializing A json string, the prompt is: the element "root" from the namespace ".. If the namespace is "" or "None ".,

When the string returned by the deserialization call interface appears: it should be the "root" element from the namespace ".. If the namespace is "" or "None "., This will cause data deserialization to fail. Sometimes, the deserialization failure (throwing an exception) is not directly reported, but the part that cannot be normally deserialized is discarded (the value is null ), I checked the information on the Internet, and said that the version used for deserialization is inconsistent with the version used for serialization, or that it is a namespace problem. I checked it and it seems that there is no problem. I really can't help it, instantiate one directly, serialize it, and compare it with the value returned by the interface. Finally, find out what the problem is.

It is because the attribute life of the class I defined myself is Keys, and the name of this attribute returned by the second interface is keys. It is very similar. If there are many attribute fields, you can't really see it, I define that the attribute starts with uppercase, and the attribute returned by the interface starts with lowercase .... If you change the attribute name to the same name as the one returned by the interface, the attribute name can be correctly parsed .. Net is very case sensitive, and I blame myself for being careless... In this remark, if you encounter a similar situation, you can see if it is the same as mine... Hope to help!

Make sure that all important fields (attributes) are consistent when you create an interface in json format later. Make sure that all the fields are in uppercase or lowercase for convenience.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.