How to obtain json-format data in C # language, without using javascript c ...,

Source: Internet
Author: User

How to obtain json-format data in C # language, without using javascript c ...,

{'Status': 1, 'data': {'LIST': [{'id': 123, 'name': 'zhuge tianxie ', 'level': 10, 'country': 1,}]}

For example, how can I obtain the id in it.
I have better answers. share with me: sort by default | sort by time. 2 answers 2012-06-25 20: 15yzy_130 | seven-level fastest answer

First, there are several errors in this json string.

The first very important error is that the json string can only contain double quotation marks instead of single quotation marks.

Second error. The comma in the json string can only be in English and cannot be in Chinese.

Third error. Remove the comma after country.

Let's talk about the conversion problem.

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

Specifically, JavaScriptSerializer. DeserializeObject converts the json string to an object.

If the json string is enclosed in braces, the actual type of the object is Dictionary <string, object>.

If it is enclosed in brackets, the actual type is object [], and the object in it is Dictionary <string, object>

Therefore, the id can be obtained only after many conversions.

We recommend that you use the JavaScriptSerializer. Deserialize method and create an object to parse json, so you do not need to convert it multiple times.

For more information, see Baidu "JavaScriptSerializer"

Hope to help you ~

By Billskate

Question
Thank you very much for helping me, But I tested it here and reported an error. Please kindly advise.
Answer
This error indicates that the json string format is incorrect.

Please follow the three points I mentioned above carefully
Question

Thank you. The json string is incorrect. However, I cannot use the JavaScriptSerializer object now. The. NetFrameWork of the server is 2.0, so it is not supported. I now use the Newtonsoft. Json. dll assembly, but a problem occurs during running. Continuously prompts that the object has not been referenced to the instance ,.

Answer
Figure you pasted ~ It seems different from your problem ~
Question

This is my current code. When Newtonsoft. Json. dll is used for conversion, the value in the object is obtained. (Rusult as Dictionary <string, object>) ["data"] as Dictionary <strin... is an exception reported here,

How can I modify the code I am writing. I have no clue at all.

 

Answer
If you want to use Newtonsoft. Json. dll for conversion, the usage of JavaScriptSerializer provided by Microsoft is definitely different.

Therefore, it cannot be obtained as I wrote previously.

The following is an example of how to obtain the data with the official Newtonsoft. Json documentation:
Comment | 2 02012-07-05 15: 5126779260 | level 5
The upstairs brothers are very thorough, but json does not seem to require double quotation marks. As long as the format is uniform, they cannot appear together with single quotation marks.
You are not using this dll. You 'd better check the document. Follow the steps

C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

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.