Simple processing of JSON in C #

Source: Internet
Author: User

Namespaces: Windows.Data.Json
In Windows runtime, you can use a JSON class to manipulate the JSON string you get, which is more intuitive than the DataContractJsonSerializer class.
For example, get an object in JSON returned by a tongue twister API:


The JSON string returned:

{
"Code":
" msg": "Success",
"Newslist": [
{
" content": "Xiao Liu and Xiao Hou,
<br\/> Racing Ball, ...
<br\/> Xiao Liu Bounce khan DC,
Xiao Liu, <br\/> Xiao Hou's momentum race,
<br\/> took more than half an hour,
<br\/> is not clear is small Liu Sheng Hou,
<br\/> or Xiao Hou Sheng xiao Liu? "
}
]
}
In this return object, there is a general data type: A number, a string, a collection of objects (an array), and a fetch for each value can do this:

1 //convert a JSON string to a JSON object2Jsonobject Jsonobject =Jsonobject.parse (JSON string);3 //Get numeric values4 DoubleCode=jsonobject.getobject () ["Code"]. GetNumber ();5 //Get String6 stringMsg=jsonobject.getobject () ["msg"]. GetString ();7 //get Array object, subscript starting from 08 stringContent=jsonobject.getobject () ["newslist"]. GetArray () [0]. GetObject () ["content"]. GetString ();

A generic array contains multiple objects, and you can use the Getnameedarray method to get the JSON array first and then iterate over its child objects.

Simple processing of JSON in C #

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.