HTML and CSS Reference
Dealing with invalid JSON
When you detect invalid JSON, it's not immediately obvious who might be the source of the problem.
The only fact you know is that the parser failed—but why? Was it because the parser has a bug? Or is
the JSON provided to the parser invalid? While developing the Flickr Viewer app you faced the error
window shown in Figure 11-8 quite a few times, often with no apparent reason. Sometimes, by simply
changing the tag the application would work just fine.
When the parser complains about invalid JSON, the first thing to do is to make sure that the JSON
content is truly valid. As shown in Figure 11-9, you can validate JSON text by copying it into the
following website: http://jsonlint.com .
FIGURE 11-9 The JSONLint website.
But how can you grab the text of the JSON you're getting as a response, so you can paste it into
the editor of JSONLint?
In Visual Studio, you place a breakpoint right onto the line that parses the content (see Figure 11-10).
The breakpoint halts execution on that line, thus giving you a chance to inspect the runtime context.