When you deserialize a JSON string in C #, you should be prompted with the element "root" from the namespace "": Encounter "None" with the name "" and the Namespace "".

Source: Internet
Author: User
Tags throw exception

When deserializing a string returned by the calling interface, it appears that the element "root" should be from the namespace "". Encounter "None" with the name "" and the Namespace "". , which causes the deserialization of the data to fail, and sometimes does not directly prompt the deserialization failure (throw exception), but instead of the normal deserialization of the partial discard (value is null), check the information on the Internet, there is the use of deserialization and serialization version inconsistency, there is a namespace problem, I checked the seemingly no problem, there is no way, directly first instantiate a, after serialization and the interface returns the value to do the comparison. Finally find out where the problem is.

Because the attribute of my own defined class is keys, the name of the property returned by the two interfaces is the keys, very similar, if the attribute field is more, not seriously, it really does not look, I define the beginning of the property is uppercase, two and the interface returns the beginning of the property is lowercase, good pit pit .... Change the property name to match the name returned by the interface, it will be able to parse correctly. NET is very sensitive to case, also blame oneself thickness careless ... In this note, I hope to encounter a similar situation can see if it is the same as my situation ... Hope to be helpful!

In the future to do the JSON format interface as far as possible to ensure that important fields (attributes) consistent, all uppercase or lowercase, convenient for others.

When you deserialize a JSON string in C #, you should be prompted with the element "root" from the namespace "": Encounter "None" with the name "" and the Namespace "".

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.