Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
	}
]



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..
Posted

1 solution

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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900