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!