© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
16 replies
Mars

✅ 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:

public class Powerup
{
    public On on { get; set; }
}

public class On
{
    public bool on { get; set; }
}
public class Powerup
{
    public On on { get; set; }
}

public class On
{
    public bool on { get; set; }
}


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:

public class Powerup
{
    public On on { get; set; }
}

public class On
{
    public On2 on { get; set; }
}

public class On2
{
    public bool on { get; set; }
}
public class Powerup
{
    public On on { get; set; }
}

public class On
{
    public On2 on { get; set; }
}

public class On2
{
    public bool on { get; set; }
}


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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Using JsonConvert to send over interface
C#CC# / help
3y ago
✅ JsonConvert.DeserializeObject return contains all null elements
C#CC# / help
3y ago
help with debugging an accessviolationexception
C#CC# / help
16mo ago
✅ Need help with debugging C++
C#CC# / help
2y ago