如何在ASP.NET中反序列化jSon数据 [英] How do I Deserialize jSon Data in ASP.NET

查看:70
本文介绍了如何在ASP.NET中反序列化jSon数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



我正在尝试反序列化我的jSon数据。输出jSon字符串如下:



Hello friends,

I am trying to Deserialize my jSon data. Output jSon string is as follow :

[
	{
		"id":1
	},
	{
		"id":2,
		"children":
		[
			{
				"id":4,
				"children":[]
			},
			{
				"id":6,
				"children":[]
			},
			{
				"id":3,
				"children":
				[
					{
						"id":5
					}
				]
			},
			{
				"id":8,
				"children":[]
			}
		]
	},
	{
		"id":7
	}
]







有多种可能数组树。我想获得Id及其相应的子元素。那么我怎样才能使用C#。请帮我举例。

谢谢..




There are n number of possible array tree. I want to get Id and their corresponding child elements. So how can i get using C#. Please help me with example.
Thank you..

推荐答案

反序列化JSON与反序列化XML一样难,但幸好有< a href =http://www.newtonsoft.com/json>一个图书馆 [ ^ ]。将库添加到您的解决方案(通过NuGet或直接下载DLL),您将能够相当容易地将JSON对象反序列化为C#对象。您需要添加一些类和方法装饰,但文档 [ ^ ]非常容易理解,并且数量众多的例子 [ ^ ]来浏览。一旦对JSON进行了反序列化,就可以将其视为任何其他对象或对象数组,并对其进行操作。如果需要,将其序列化也很简单。祝你好运!
Deserializing JSON is just about as hard as deserializing XML, but thankfully there's a library for that[^]. Add the library to your solution (either via NuGet or downloading the DLLs directly) and you'll be able to deserialize JSON objects into C# objects fairly easiliy. There are some class and method decorations you'll have to add but the documentation[^] is really easy to follow and there are pleanty of examples[^] to look through. Once you have deserialized your JSON you can then treat it like any other object or array of objects and manipulate it as such. Serialzing it back if needed is pretty straight forward as well. Good luck!


这篇关于如何在ASP.NET中反序列化jSon数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆