Simple processing method of JSON in C # _c# tutorial

Source: Internet
Author: User
Tags numeric value

Namespaces: Windows.Data.Json

In Windows runtime, you can use the JSON class to manipulate the obtained JSON string, which is more intuitive than the DataContractJsonSerializer class operation.

For example get an object in the JSON returned by a tongue twister API:

The returned JSON string:

{"
code": "
msg": "Success",
"newslist": [
{
"content": "Xiao Liu and Xiao Hou,
<br\/> competition Pat Skin Ball..
<br\/> Xiao Liu Bounce,
<br\/> xiao Hou Momentum race Xiao Liu,
<br\/> patted for more than half an hour,
<br\/> not clear is small Liu Sheng Hou, 
    <br\/> Hou Sheng Xiao Liu? "
}
]
}

In this return object, there is a general data type: A number, a string, a collection of objects (arrays), which can be obtained for each value:

Converts a JSON string into a JSON object
jsonobject jsonobject = jsonobject.parse (JSON string);
Gets the numeric value
double code=jsonobject.getobject () [code]. GetNumber ();
Gets
the string msg=jsonobject.getobject () ["MSG"]. GetString ();
Gets the array object, with the subscript starting at 0
string content=jsonobject.getobject () ["Newslist"]. GetArray () [0]. GetObject () ["Content"]. GetString ();

There are multiple objects in a generic array, and you can use the Getnameedarray method to get the JSON array first and then iterate over its child objects.

The above is a small set up to introduce the C # in the JSON simple processing method of all the narration, I hope to help you, if you have any questions welcome to my message, small series will promptly reply to everyone, here also thank you for your support cloud Habitat community site!

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.