Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using System.Json for non-Silverlight projects?

Tags:

json

c#

.net

Any idea on how to do it? If not possible, what's a good JSON library for C#?

like image 258
Patrick Avatar asked Apr 22 '09 04:04

Patrick


1 Answers

System.Json is now available in non-Silverlight projects via NuGet (.Net's package management system) and is hopefully going to be released as part of the core framework in vnext. The NuGet package is named JsonValue.

Imagine that we have the following JSON in the string variable json:

[{"a":"foo","b":"bar"},{"a":"another foo","b":"another bar"}]

We can get write the value "another bar" to the console using the following code:

using System.Json;
dynamic jsonObj = JsonValue.Parse(json);
var node = jsonObj[1].b;
System.Console.WriteLine(node.Value);
like image 70
Richard Fawcett Avatar answered Sep 30 '22 19:09

Richard Fawcett