Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON object undefined in Internet Explorer 8

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?

like image 529
keybored Avatar asked Jan 17 '11 16:01

keybored


People also ask

Why is JSON value undefined?

The JSON-unsafe values on the other hand return : undefined if they are passed as values to the method. null if they are passed as an array element. nothing if passed as properties on an object.

Is JSON supported by all browsers?

All modern browsers support native JSON encoding/decoding (Internet Explorer 8+, Firefox 3.1+, Safari 4+, and Chrome 3+). Basically, JSON. parse(str) will parse the JSON string in str and return an object, and JSON. stringify(obj) will return the JSON representation of the object obj .

Does JSON Stringify remove undefined?

JSON. stringify will omit all object attributes that are undefined .


1 Answers

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.

like image 157
Andy E Avatar answered Sep 21 '22 04:09

Andy E