0

I'm a newbie trying stuff out!

So i'm trying to deserialize a json string returned from an api and get the int status_code out of their returned json

overall BestGamer = JsonConvert.DeserializeObject<overall>(thicky);

Console.WriteLine(BestGamer);
{
"updated":"2020-01-13T05:08:58+0000"
"term":"bojack"
"status_code":200
"variant":"ivafull"
}

And i made a class here

public class overall
    {
        public int status_code { get; set; }
    }

but whenever i compile and run it it just says TestConsole (name of my project) .overall (TestConsole.overall).

I'm using NewtonSoft to deserialize

If anyone could help me out with this i'd be very grateful :)

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
Arkane
  • 1
  • 1
  • `Console.WriteLine(BestGamer.status_code);` will do the trick. – cassandrad May 08 '20 at 23:25
  • 2
    https://stackoverflow.com/questions/10278049/why-when-would-it-be-appropriate-to-override-tostring – Retired Ninja May 08 '20 at 23:32
  • `Console.WriteLine(BestGamer);` implicitly calls `ToString()` on the `BestGamer` object and prints that. If you want to stick with that syntax, then the `ToString()` method has to be overridden so that it returns the text you want to print, instead of the default (i.e. the name of the type). If you don't want to override `ToString()`, then just print the text you want instead of that object (e.g. the `status_code` property value). – Peter Duniho May 08 '20 at 23:45
  • Do not rewrite posts to make them mean something completely different. Use edits _only_ for the purpose of adding information or clarifying the post. If you have a new question, post that question as a new question. – Peter Duniho May 09 '20 at 02:34

0 Answers0