Parse json string using JSON.NET

前端 未结 3 1878
别跟我提以往
别跟我提以往 2020-12-12 17:31

I have a string like the following in C#. I need to loop through and create an HTML table output. I tried with JSON.NET but couldn\'t figure out how to retrieve the keys (Na

3条回答
  •  情深已故
    2020-12-12 18:09

    I did not test the following snippet... hopefully it will point you towards the right direction:

        var jsreader = new JsonTextReader(new StringReader(stringData));
        var json = (JObject)new JsonSerializer().Deserialize(jsreader);
        var tableRows = from p in json["items"]
                     select new
                     {
                         Name = (string)p["Name"],
                         Age = (int)p["Age"],
                         Job = (string)p["Job"]
                     };
    

提交回复
热议问题