C
C#11mo ago
SWEETPONY

✅ How to get value from json object by path?

I have this in json:
"Patterns": {
"EventName": "eventInfo.name",
"EventTaskId": "eventInfo.id"
}
"Patterns": {
"EventName": "eventInfo.name",
"EventTaskId": "eventInfo.id"
}
Than I just do this:
var patterns = configuration
.GetRequiredSection(nameof(Patterns))
.Get<Patterns>();
var patterns = configuration
.GetRequiredSection(nameof(Patterns))
.Get<Patterns>();

and all I need no is get information from json using this patterns. how can I do it?
1 Reply
SWEETPONY
SWEETPONYOP11mo ago
my solution:
var patterns = configuration
.GetRequiredSection(nameof(Patterns))
.Get<Patterns>();

var message = JObject.Parse(context.Message.ToString());
var eventName = message.SelectToken(patterns.EventName);
var eventTaskId = message.SelectToken(patterns.EventTaskId);
var patterns = configuration
.GetRequiredSection(nameof(Patterns))
.Get<Patterns>();

var message = JObject.Parse(context.Message.ToString());
var eventName = message.SelectToken(patterns.EventName);
var eventTaskId = message.SelectToken(patterns.EventTaskId);
but I don't think it is good enough
Want results from more Discord servers?
Add your server