✅ JsonConvert debugging help
Hello! I'm having a hard time figuring out how to solve an issue where JsonConvert.DeserializeObject is struggling to parse a weird data structure.
Essentially I'm getting an object like this: {"powerup":{"on":{"on":{"on":true}}}}
There are more objects and values, but I'm omitting them as they're not relevant to the parsing error
In other words, an object called powerup with an object called on, that has an object called on, that has a bool called on. Very odd data structure, I know, but unfortunately this is what the API I'm consuming is giving me.
A json converter tool suggested this:
However, this reads to a parsing error saying that { after the second on objects : is an unexpected character. Which makes sense, as it's expecting a bool, not an object. So I tried to fix it by doing this:
However, now I'm getting the error that it fails to convert a boolean value to the type On2, which seems to suggest that it's now suddenly reading it correctly as a bool and trying to set the On2 on variable with this bool value.
I'm very confused at this point. Anyone have any idea what's going on here?
9 Replies
quictype.io generated the following:
see if it works
Although it was generated for
System.Text.Json
, and you seem to be using Newtonsoft for some reason
Just change JsonPropertyName
to JsonProperty
and it'll work with NewtonsoftGonna test it now, but that does seem very promising
Got this: "Error converting value True to type 'namespace.OnOn'"
Seems to be the same error as when I tried On2
Angius#1586
REPL Result: Success
Result: Root
Compile: 578.397ms | Execution: 60.214ms | React with ❌ to remove this embed.
Seems to be working
At least with STJ
Hmm, maybe I'll give it a shot with STJ instead then. Didn't pick newtonsoft for any particular reason, it was just the first option I found
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Angius#1586
Just change
JsonPropertyName
to JsonProperty
and it'll work with NewtonsoftQuoted by
<@!85903769203642368> from #JsonConvert debugging help (click here)
React with ❌ to remove this embed.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
There, finally got it to work. Ended up with some new issues, but that was just quicktype interpreting float values as long. STJ did the trick
I'll make sure I avoid newtonsoft in the future, thanks for the help!