Parsing a JSON array using Json.Net

前端 未结 2 1250
挽巷
挽巷 2020-11-28 04:53

I\'m working with Json.Net to parse an array. What I\'m trying to do is to pull the name/value pairs out of the array and assign them to specific variables while parsing the

2条回答
  •  误落风尘
    2020-11-28 05:17

    You can get at the data values like this:

    string json = @"
    [ 
        { ""General"" : ""At this time we do not have any frequent support requests."" },
        { ""Support"" : ""For support inquires, please see our support page."" }
    ]";
    
    JArray a = JArray.Parse(json);
    
    foreach (JObject o in a.Children())
    {
        foreach (JProperty p in o.Properties())
        {
            string name = p.Name;
            string value = (string)p.Value;
            Console.WriteLine(name + " -- " + value);
        }
    }
    

    Fiddle: https://dotnetfiddle.net/uox4Vt

提交回复
热议问题