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 #