using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
string json = @"
{
""module"": {
""serial"": ""3"",
""label"": ""A"",
""lat"": ""B"",
""long"": ""C"",
""channels"": [
{
""channel"": ""1"",
""label"": ""Channel 1"",
""AnalogInput"": ""13"",
""AnalogInputRaw"": ""13"",
""AnalogInputScale"": ""Raw"",
""DigitalInput"": ""Off""
},
{
""channel"": ""2"",
""label"": ""Channel 2"",
""AnalogInput"": ""13"",
""AnalogInputRaw"": ""13"",
""AnalogInputScale"": ""Raw"",
""DigitalInput"": ""On""
},
{
""channel"": ""3"",
""label"": ""Channel 3"",
""AnalogInput"": ""14"",
""AnalogInputRaw"": ""14"",
""AnalogInputScale"": ""Raw"",
""DigitalInput"": ""On""
},
{
""channel"": ""4"",
""label"": ""Channel 4"",
""AnalogInput"": ""14"",
""AnalogInputRaw"": ""14"",
""AnalogInputScale"": ""Raw"",
""DigitalInput"": ""On""
}
],
""variables"": [
{
""1"": ""0""
},
{
""2"": ""0""
},
{
""3"": ""1""
},
{
""4"": ""0""
}
]
}
}";
JObject originalObject = JObject.Parse(json);
string[] analogInputTrueValues = originalObject.Descendants()
.OfType<JProperty>()
.Where(p => p.Name == "AnalogInput")
.Select(x => x.Value.ToString())
.ToArray();
Console.WriteLine(string.Join(", ", analogInputTrueValues));
}
}
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
string json = @"
{
""module"": {
""serial"": ""3"",
""label"": ""A"",
""lat"": ""B"",
""long"": ""C"",
""channels"": [
{
""channel"": ""1"",
""label"": ""Channel 1"",
""AnalogInput"": ""13"",
""AnalogInputRaw"": ""13"",
""AnalogInputScale"": ""Raw"",
""DigitalInput"": ""Off""
},
{
""channel"": ""2"",
""label"": ""Channel 2"",
""AnalogInput"": ""13"",
""AnalogInputRaw"": ""13"",
""AnalogInputScale"": ""Raw"",
""DigitalInput"": ""On""
},
{
""channel"": ""3"",
""label"": ""Channel 3"",
""AnalogInput"": ""14"",
""AnalogInputRaw"": ""14"",
""AnalogInputScale"": ""Raw"",
""DigitalInput"": ""On""
},
{
""channel"": ""4"",
""label"": ""Channel 4"",
""AnalogInput"": ""14"",
""AnalogInputRaw"": ""14"",
""AnalogInputScale"": ""Raw"",
""DigitalInput"": ""On""
}
],
""variables"": [
{
""1"": ""0""
},
{
""2"": ""0""
},
{
""3"": ""1""
},
{
""4"": ""0""
}
]
}
}";
JObject originalObject = JObject.Parse(json);
string[] analogInputTrueValues = originalObject.Descendants()
.OfType<JProperty>()
.Where(p => p.Name == "AnalogInput")
.Select(x => x.Value.ToString())
.ToArray();
Console.WriteLine(string.Join(", ", analogInputTrueValues));
}
}
No comments:
Post a Comment