Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can you deserialize a JSON string using JSON.NET that uses empty quotes rather than null for a field
    primarykey
    data
    text
    <p>I am trying to deserialize some reddit comments (returned in JSON) using JSON.NET. I have come across a problem where the Comment has a field "Replies", which is either another Comment object, or empty quotes (""). The problem is the JSON.NET deserializer throws an exception when deserializing a field that is expecting an object but finds "" (as I expect it is looking for null rather than "").</p> <p>Example:</p> <pre><code>"data":{ "body":"We were being trolled. ", "subreddit_id":"t5_2qh1i", "author_flair_css_class":null, "created":1318984933.0, "author_flair_text":null, "downs":1, "author":"evange", "created_utc":1318959733.0, "body_html":"&lt;div class=\"md\"&gt;&lt;p&gt;We were being trolled.&lt;/p&gt;&lt;/div&gt;", "levenshtein":null, "link_id":"t3_lghhj", "parent_id":"t3_lghhj", "likes":null, "replies":"", "id":"c2shf1a", "subreddit":"AskReddit", "ups":6, "name":"t1_c2shf1a" } </code></pre> <p>And then this is the :</p> <pre><code>"data":{ "body":"Dude, it was a Roll Troll. Forget it.", "subreddit_id":"t5_2qh1i", "author_flair_css_class":null, "created":1318985233.0, "author_flair_text":null, "downs":1, "author":"youngmonk", "created_utc":1318960033.0, "body_html":"&lt;div class=\"md\"&gt;&lt;p&gt;Dude, it was a Roll Troll. Forget it.&lt;/p&gt;&lt;/div&gt;", "levenshtein":null, "link_id":"t3_lghhj", "parent_id":"t3_lghhj", "likes":null, "replies":{ "kind":"Listing", "data":{ "modhash":"", "children":[....etc </code></pre> <p>Is there a way to deserialize this with JSON.NET, or will I have to do a RegEx to search for "Replies": "" to change all those empty quotes to null?</p> <p>Thanks!</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.
 

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