How the C # language obtains JSON-formatted data without JavaScript in C # ...

Source: Internet
Author: User

{' state ': 1, ' data ': {' list ': [{' id ': 123, ' name ': ' Zhugetian ', ' Level ': ten, ' Country ': 1,}]}

For example, I want to get the ID inside how to implement.
I have a better answer.Share to:Sort By default | Sort by Time 2 answers2012-06-25 20:15yzy_130 | Level seven fastest answer

First of all, there are several errors in this JSON string.

The first very important error, the JSON string can only use double quotation marks, cannot use single quotation marks, this single double quotation mark meaning is not in quotation marks is the string, but the JSON stipulation

The second error, the comma within the JSON string can only be used in English, not in Chinese

The third error, the comma after country, is removed.

Again, the conversion problem

The simplest way is to use the. NET built-in JavaScriptSerializer class,

Where Javascriptserializer.deserializeobject converts the JSON string to object

If the JSON string is wrapped in curly braces, the actual type of this object is dictionary<string, object>

If wrapped in brackets, the actual type is object[], and the object is dictionary<string, object>

So there's a lot of conversions to get the ID eventually.

It is recommended to use the Javascriptserializer.deserialize method and create entities to parse JSON without having to convert multiple times

Specific practices please Baidu "JavaScriptSerializer"

Hope to help you ~

by billskate

Ask
Thank you very much for helping me, but I tested in my here, error Oh, please expert pointing ah.
Reply
This error indicates that you have an error in JSON string format

Please carefully follow the three-point check I said earlier.
Ask

Thank you, the JSON string is wrong. But I can't now use the JavaScriptSerializer object, now the server's. NETFramework is 2.0, so it is not supported. I'm replacing it with Newtonsoft.Json.dll, but there's a problem with running it. You are constantly prompted not to reference the object to the instance.

Reply
The picture you posted ~ doesn't seem to agree with your question ~
Ask

This is my current code, I used the Newtonsoft.Json.dll conversion to get the object inside the value. (((Rusult as Dictionary<string, object>) ["Data"] as Dictionary<strin ... Is the anomaly in this newspaper,

How to modify the code I write now. I really don't have a clue.

Reply
If you want to use Newtonsoft.Json.dll to convert, this and Microsoft provides the JavaScriptSerializer usage certainly is different

So I can't get it by the way I wrote it.

To get the example of LINQ to JSON included with Newtonsoft.json official documentation:
Comments | 2 0 2012-07-05 15:5126779260 | level five
The brother upstairs is very thorough, but JSON does not seem to stipulate that it must be double quotes Oh, as long as the format is uniform, you cannot appear together with double quotation marks.
This DLL you do not ah, it is best to check the documentation. Follow the steps to

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.