C
C#•2y ago
Navi

Json array with multiple types to object

Hi, I've got the following JSON Array of an array (that I can't change)
"values": [
[
"2712",
1
],
[
"2.40",
1
]
],
"values": [
[
"2712",
1
],
[
"2.40",
1
]
],
How would I go about deserializing this using system.text.json? I'm fine with a solution that gives me a class (with a string and int as properties) or with casting the int to a string somehow and thus having an string[][]
4 Replies
Thinker
Thinker•2y ago
Wouldn't object[][] work...?
Navi
NaviOP•2y ago
I was hoping for something more elegant 😛
Thinker
Thinker•2y ago
Otherwise depending on how much effort you're willing to put in, you could maybe create a type which represents either an integer or a string, then write a custom JSON converter for it.
Navi
NaviOP•2y ago
Hmm, object[][] makes it a JsonElement and not a string/int 🤔 Figured it out with a custom converter after all Thanks
Want results from more Discord servers?
Add your server