JSON object undefined in Internet Explorer 8

keybored picture keybored · Jan 17, 2011 · Viewed 93.9k times · Source

Currently I'm writing a JavaScript file and have the following line:

var res = "JSON=" + JSON.stringify(result);

result is being set just above this line. The issue I'm having is that IE8 (IE8 only, that is) is reporting to me that JSON is undefined somehow. I'm not sure what to make of this since, as I understood it, IE8 is a browser that implemented JSON support. Does anyone have any idea what might be going on?

Answer

Andy E picture Andy E · Jan 17, 2011

Make sure you're actually in IE 8 mode by using the preferred method, a standards doctype...

<!DOCTYPE html>

...or the undesired method, the X-UA-Compatible meta tag/header...

<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />

See Defining Document Compatibility for more information.