Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see a couple of problems with what you have. The first is the structure of the classes you have to deserialize the json data into. Manually writing up classes for this is really tedious and error-prone, and so I generally like to use <a href="http://json2csharp.com/" rel="noreferrer">this site</a> to plug in the json and get out the classes I need and rename as appropriate. I'd then go and find the <a href="https://github.com/reddit/reddit/wiki/API%3A-info.json" rel="noreferrer">api docs</a> for the data to fill in any gaps in the classes that the data simply just didn't have.</p> <p>After that, you only need to deserialize a single instance of the root object class that you now have, rather than a List of them, so something like:</p> <pre><code>RootObject topics = JsonConvert.DeserializeObject&lt;RootObject&gt;(json); </code></pre> <p>One other note is that when you're deserializing your data, in your code, you're currently declaring a new local variable called <code>topics</code> which hides your member variable that is also called <code>topics</code> in that particular scope and so if you ever inspect that member variable, you would see that it won't have any data in it. You don't want to be declaring a new variable there, you just want to use the existing member variable, so instead of the previous line, you would just want to do:</p> <pre><code>topics = JsonConvert.DeserializeObject&lt;RootObject&gt;(json); </code></pre> <p>Or even <code>this.topics</code> if you want to be really explicit and clear about where that variable is coming from.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload