2

I need to Support IE7. In IE10 developers tool I'm setting "Document mode to IE7 standards" but it still says "JSON is not defined" here is my test HTML code:

Web site: <span id="wurl"></span><br/>
Title: <span id="wtitle"></span>
<script type="text/javascript" src="http://knivesandtools.nl/2011/js/json2.js"></script>
<script type="text/javascript">
// example of what is received from server
var jsnstr = '{"url": "http://coursesweb.net/", "title": "Web Development Courses", "users": 1500}';

// parse the "jsnstr", and store the JSON object in "obj"
var obj = JSON.parse(jsnstr);

// uses the JavaScript object, adds the values from "url", and "title" in web page
document.getElementById('wurl').innerHTML = obj.url;
document.getElementById('wtitle').innerHTML = obj.title;
</script>
Mike Ezzati
  • 2,968
  • 1
  • 23
  • 34
  • If you support IE 7, you should be testing in real browser. Set up virtual machine or use [modern.IE](http://www.modern.ie/en-us). – Pavlo Sep 27 '13 at 08:18
  • 1
    problem is some clients are viewing our pages with IE10,9 but with Document mode IE7 standards . and they complain about this problem. they are not usinng IE7 actually so I need to check it this way. even tag is not helping sometimes. – Mike Ezzati Sep 27 '13 at 08:26

2 Answers2

3

It should work with JSON.parse(str).

However, since you tagged this question with jQuery, you could use $.parseJSON(str).

Double check that json2.js is loaded correctly.

I've pasted a minified version and tried it successfully in ie7:

http://jsfiddle.net/7bmRe/2/show/

Here is the source, please use this version (found here).

Community
  • 1
  • 1
Johan
  • 35,120
  • 54
  • 178
  • 293
-1

IE7 mode don't support JSON object, if you want to parse json with it you'll need to use some different parser.

I supose that you are importing json2.js to that, you should check it's documentation to see how it's used.

Bardo
  • 2,470
  • 2
  • 24
  • 42