English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Namespace: Windows.Data.Json
In Windows Runtime, you can use the Json class to operate the obtained Json string, which is more intuitive than the DataContractJsonSerializer class.
For example, to obtain an idiom API return Json object:
//The returned Json string:
{ "code":200, "msg":"success", "newslist":[ { "content":"Xiao Liu and Hou, <br/>Play with a ball, ... <br/>Xiao Liu sweating while shooting the ball <br/>Xiao Hou is as energetic as Xiao Liu, <br/>Shot for more than half an hour, <br/>Can't tell if it's Xiao Liu who is better than Xiao Hou, <br/>Or is it Xiao Hou who is better than Xiao Liu?63;" } ] }
In this returned object, it contains common data types: numbers, strings, object collections (arrays), and for each value, you can do as follows:
//Convert Json string to Json object JsonObject jsonObject = JsonObject.Parse(Json string); //Get numerical value double code = jsonObject.GetObject()["code"].GetNumber(); //Get string string msg = jsonObject.GetObject()["msg"].GetString(); //Get array object, index starts from 0 string content = jsonObject.GetObject()["newslist"].GetArray()[0].GetObject()["content"].GetString();
Generally, an array will contain multiple objects. At this time, you can use the GetNameedArray method to first obtain this JSON array, and then traverse its child objects.
The above is the full description of the simple processing method of JSON in C# introduced by the editor to everyone. I hope it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time. At the same time, I would also like to express my sincere gratitude to everyone for their support of the Nao yan tutorial website!
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been edited by humans, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)