CSharp · Console
using System;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
string json = @"
{
""001"": {
""peers"": [
{
""id"": 0,
""server"": ""1.1.1.1:80"",
""name"": ""1.1.1.1:80"",
""backup"": false,
""weight"": 1,
""state"": ""up"",
""active"": 0,
""requests"": 0,
""responses"": {
""1xx"": 0,
""2xx"": 0,
""3xx"": 0,
""4xx"": 0,
""5xx"": 0,
""total"": 0
},
""sent"": 0,
""received"": 0,
""fails"": 0,
""unavail"": 0,
""health_checks"": {
""checks"": 0,
""fails"": 0,
""unhealthy"": 0
},
""downtime"": 0
},
{
""id"": 1,
""server"": ""127.0.0.1:8888"",
""name"": ""127.0.0.1:8888"",
""backup"": false,
""weight"": 1,
""state"": ""down"",
""active"": 0,
""requests"": 0,
""responses"": {
""1xx"": 0,
""2xx"": 0,
""3xx"": 0,
""4xx"": 0,
""5xx"": 0,
""total"": 0
},
""sent"": 0,
""received"": 0,
""fails"": 0,
""unavail"": 0,
""health_checks"": {
""checks"": 0,
""fails"": 0,
""unhealthy"": 0
},
""downtime"": 0
}
],
""keepalive"": 0,
""zombies"": 0,
""zone"": ""001""
},
""002"": {
""peers"": [
{
""id"": 0,
""server"": ""1.1.1.2:80"",
""name"": ""1.1.1.2:80"",
""backup"": false,
""weight"": 1,
""state"": ""up"",
""active"": 0,
""requests"": 0,
""responses"": {
""1xx"": 0,
""2xx"": 0,
""3xx"": 0,
""4xx"": 0,
""5xx"": 0,
""total"": 0
},
""sent"": 0,
""received"": 0,
""fails"": 0,
""unavail"": 0,
""health_checks"": {
""checks"": 0,
""fails"": 0,
""unhealthy"": 0
},
""downtime"": 0
},
{
""id"": 1,
""server"": ""127.0.0.1:8888"",
""name"": ""127.0.0.1:8888"",
""backup"": false,
""weight"": 1,
""state"": ""down"",
""active"": 0,
""requests"": 0,
""responses"": {
""1xx"": 0,
""2xx"": 0,
""3xx"": 0,
""4xx"": 0,
""5xx"": 0,
""total"": 0
},
""sent"": 0,
""received"": 0,
""fails"": 0,
""unavail"": 0,
""health_checks"": {
""checks"": 0,
""fails"": 0,
""unhealthy"": 0
},
""downtime"": 0
}
],
""keepalive"": 0,
""zombies"": 0,
""zone"": ""002""
}
}";
var obj = JObject.Parse(json);
foreach (JProperty prop in obj.Properties())
{
var item = (JObject)prop.Value;
var zone = (string)item["zone"];
var keepalive = (int)item["keepalive"];
Console.WriteLine($"Zone: {zone} keepalive: {keepalive}");
}
}
}