CSharp · Console
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
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 dict = JsonConvert.DeserializeObject<Dictionary<string, Item>>(json);
foreach (var kvp in dict)
{
Item item = kvp.Value;
Console.WriteLine($"Zone: {item.zone} keepalive: {item.keepalive}");
}
}
}
public class Item
{
public List<Peer> peers { get; set; }
public int keepalive { get; set; }
public int zombies { get; set; }
public string zone { get; set; }
}
public class Peer
{
public int id { get; set; }
public string server { get; set; }
public string name { get; set; }
public bool backup { get; set; }
public int weight { get; set; }
public string state { get; set; }
public int active { get; set; }
public int requests { get; set; }
public Responses responses { get; set; }
public int sent { get; set; }
public int received { get; set; }
public int fails { get; set; }
public int unavail { get; set; }
public HealthChecks health_checks { get; set; }
public int downtime { get; set; }
}
public class Responses
{
[JsonProperty("1xx")]
public int code_1xx { get; set; }
[JsonProperty("2xx")]
public int code_2xx { get; set; }
[JsonProperty("3xx")]
public int code_3xx { get; set; }
[JsonProperty("4xx")]
public int code_4xx { get; set; }
[JsonProperty("5xx")]
public int code_5xx { get; set; }
public int total { get; set; }
}
public class HealthChecks
{
public int checks { get; set; }
public int fails { get; set; }
public int unhealthy { get; set; }
}