douglascrockford / JSON-js

JSON in JavaScript
http://www.JSON.org/
8.7k stars 4.59k forks source link

I get an error when trying to load JSON in IE 8 in compatibility mode #76

Closed malhayek2014 closed 8 years ago

malhayek2014 commented 8 years ago

I am trying to convert an object to json string in IE 8 comparability mode.

Here is what I have done. I added a new file in my resources folder and called it json2.js Then from the JSON-js project I copied the json2.js file content and pasted it into my json2.js file and included the file resources/json2.js into my app.

Now, I am trying to use JSON.stringify to convert an object into json string which is giving me the following error

But when I use JSON.stringify(records) in IE8 under compatibility mode I get this error

Line: 314
Char: 21
Error: Invalid procedure call or argument
Code: 0

Here is what I have done

HTML Markup

<div id="d">Click Here</div>
<div id="s"></div>

Javascript code

var records = {};

$(function(e){

   records['123'] = {};
   records['456'] = {};

   records['123']['rec_id'] = 4456;
   records['123']['created_at'] = '';
   records['123']['assigned_at'] = '';
   records['123']['sys_id'] = 1745;

   records['456']['rec_id'] = 4456;
   records['456']['created_at'] = '';
   records['456']['assigned_at'] = '';
   records['456']['sys_id'] = 1745;

   $.each(records, function(callID, record){

            record['campaign_id'] = '1';
            record['offset'] = 123;
            record['attempt'] = '7';
            record['phone'] = '800-123-4567';
            record['identity'] = 123;
            record['code'] = 'Some Code';
            record['notes'] = 'Some notes';
            record['completed_by'] = 'Mike A';
            record['name'] = null;

            record['completed_at'] = "";

   });

   $('#d').click(function(e){
        $('#s').text(  JSON.stringify(records)  );
   });

});

the above code can be found in the following jFiddle https://jsfiddle.net/4632wf5n/

What can I do to convert my object into json string in IE8 with comparability mode?

XiaomiYe commented 8 years ago

how is IE6

douglascrockford commented 8 years ago

It seems that you are doing something wrong. Please let me know when you figure out what it is.