✅ getting all the keys of a json object
The json input I have is:
What I want as output is:
The json is contained in a JsonObject, and I'm trying to make a method to do what I'm talking about:
But the output I'm getting is:
42 Replies
got it
another question
each key has a value of an array of strings
I want to either get the last string of that array of strings, or if the array is empty, get "None"
https://github.com/Axlefublr/ChoreTracker/blob/main/ChoreTracker/ChoreManager.cs
so umh
you just want to get the keys from the root object?
and ignore the values?
done that already ☑️
now I wanna do the exact opposite of this
I want to get the last value in the array (which is the value)
last value in the array for each key?
Currently, your arrays are all empty
or do you just want to fetch the "value", aka the empty arrays?
yes! they are currently empty, but aren't going to be eventually
if they're empty, I want to get the string "None", if they have at least one value, then the last one
I think I know how I wanna approach this
instead of storing an array of values, I should just store a single value
it makes more sense for the app anyway
oh you already did it sorry hon I wasted your breath 😭
¯\_(ツ)_/¯
regardless, you should be doing this with serialization instead of JsonObject
hmmm
var data = JsonSerializer.Deserialize<Dictionary<string, string[]>>(json);
that makes me have to create types to serialize into
thats it.
nope.
oh.
the json above is a dictionary
with string keys and string array/lists
I have a feeling this is going to be a recurring theme: why does C# provide a more annoying way to do the same thing then?
ahahahhahaahaa
its a general purpose language. it has to support everything
there will always be more than one way of doing something
that's why ahk is my favorite language!
ahk! support everything but actually anything useful!
System.Text.Json
is just a library, you could write your own json library if you wanted.I shit you not it has a way to sort strings but not arrays 💀
¯\_(ツ)_/¯
it's very in character of me ahahahahahah
I wrote a window manager recently
same code but with a dictionary
much better
type safety etc
and linq
which is exactly what I was missing
well, the old one used linq too :p
because I knew about LastOrDefault, and it was exactly what I was looking for
LastOrDefault()?.ToString() ?? None
oh nonono I mean in my solution
ah
yours is wonderful sweetheart
thank you for helping me!!
welcome is you.
I feel like we beginners like to overcomplicate things sometimes because we think it's the actual way to do it
yes 🙂
I see this from the perspective you're currently in all the time
also.. $close
Use the
/close
command to mark a forum thread as answeredoh cool you can call your bot inside of a message 🤯
yeah the dollarsign stuff is "tags", its a short way to invoke a pre-written message from the bot
we have a whole bunch of them for common replies, links, resources etc
and memes, ofc
same same
we do on our server as well
but there you have to start a message with a dot command
like you say
.ask
and it displays the message
but if you say hey you should .ask here instead!
it won't worktags are not commands either, we can add new ones without restarting the bot.
and they have ownerships etc. its good.
yeah same
.ask is a special command
modix source is opensource too, if you want to check how it was done
but we have .tag tagName for the usual stuff