简体   繁体   中英

Deserializing JSON to C# using NewtonSoft

I have the below JSON

[{"name":"sEcho","value":3},{"name":"iColumns","value":7}]

When i deserialize using JOSN.NET i ll get o/p as List of name and values

name sEcho
value 3

Is it possible somehow to get like

sEcho 3
IColumn 7

This is the string am getting from JQUERY DataTable to my controller and am trying to convert into a class using Newton soft .

How do i achieve this?

You can convert it to dictionary

string json = @"[{""name"":""sEcho"",""value"":3},{""name"":""iColumns"",""value"":7}]";

var dict = JArray.Parse(json)
           .ToDictionary(x => (string)x["name"], x => (string)x["value"]);

Console.WriteLine(dict["sEcho"]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM