5

I am trying to use JSON.stringify in my javascript page (EXTJS) code but it's giving me JSON is undefined error. Error happends only in IE (ver.10). This code will work in FF and Chrome. Below is a sample code that I am trying to use. Why is it failing? This seems like a valid example and works in other browsers. Thanks in advance.

var contact = new Object(); 
contact.firstname = "Joe";
contact.surname = "Smith";
contact.gendere= "male";
var jsonText = JSON.stringify(contact);
2
  • What happens when you use {} instead of new Object()? Does it work if you use a hardcoded object like { firstname : 'Joe', surname : 'Smith', gendere : 'male' }? Commented Jun 18, 2013 at 16:01
  • Hi schlingel, I get same error "JSON undefined" when I hard code. Commented Jun 18, 2013 at 16:12

3 Answers 3

2

Use <!DOCTYPE html> if you only need to support IE10. If you need to use earlier versions of IE (some people still need to support IE6) you can use the JS implementation of JSON: https://github.com/douglascrockford/JSON-js

Sign up to request clarification or add additional context in comments.

7 Comments

Ok I tried <!DOCTYPE html> but no effect, same problem, JSON undetified error. Any other ideas?
@JS11 did you try using the JSON-js implementation from my response?
Hi Nirk, I am currently using json2.js and i notice this on the link you recomended: "json.js: This file does everything that json2.js does. It also adds a toJSONString method and a parseJSON method to Object.prototype. Use of this file is not recommended."
Use of this file is not recommended - portion is what confuses me
@JS11 use the file json2.js -- that replicates the JSON object (with parse and stringify). json.js was an older interface
|
2

Put

<!DOCTYPE html>

at the top of your document (and of course remove any other doctype you might have).

Without it, IE10 is in a weird compatibility mode where many "new" features aren't available, for example JSON.

3 Comments

This is truth,and if you are doing new development, the only solution. HOWEVER, if you are maintaining and old page that relies on the broken layout, you can include json.js from the json.org website.
@JeremyJStarcher That's true. But do people still maintain applications compatible with IE8 and not compatible with other browsers ?
Not so much on public facing websites, but there are still a lot of intraweb and private websites that have not been brought up to date. A lot are limited to older IE engines to do ActiveX dependencies.
2

You have the framework already, use it: Ext.JSON.encode/decode http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.JSON

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.