-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJTokenSerialization.linq
33 lines (27 loc) · 1.05 KB
/
JTokenSerialization.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<Query Kind="Statements">
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>Newtonsoft.Json.Linq</Namespace>
</Query>
var testData = @"{
'Command': 'GET',
'Protocol': 'https',
'EndPoint': '172.27.145.155:5100/api/ping',
'SuccessfulResponses' = '200,204',
'NumberOfSuccessiveFailuresBeforeDisabling': '10',
'PingInterval': '300',
'DisableThreshhold': '10',
'SlackAlertUrl': 'https://hooks.slack.com/services/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',
'SlackAlertChannel': '#cpas_alerts'
}";
var token = JToken.Parse(testData);
var myProperties = new[] { "endpoint", "protocol", "command" };
var jObject = token.Value<JObject>();
var clientData = jObject.Properties()
.Where(property => myProperties.Contains(property.Name.ToLowerInvariant()))
.ToDictionary(property => property.Name.ToLowerInvariant(), property => property.Value);
var endpoint = clientData["endpoint"];
var protocol = clientData["protocol"];
var command = clientData["command"];
endpoint.Dump();
protocol.Dump();
command.Dump();