0

I have an application that runs inside of a viewer that forces the app to run in IE8 compatability mode. I understand IE 8 is not longer supported by Microsoft and it is a very bad browser, but it is a limitation that I have to deal with since I have no control over my Viewer. I am trying to convert an object into json string.

Here is what I have done so far. First, I create JavaScript object like this

   var records = {};

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

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

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


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

            record['campaign_id'] = '1';
            record['offset'] = getCurrentOffset();
            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'] = 'Mike A';

            record['completed_at'] = getCurrentTime();

   });

Now, I want to convert my records object into json string.

In modern browsers I can use JSON.stringify() to convert the object with no problem. However, JSON.stringify() does not work in IE 8 compatability mode.

I found alternative solution to convert the object into json string jQuery JSON plugin

I tried to convert my object using jQuery JSON plugin like so

$.toJSON(records);

But, that is giving me the following error

Line: 116 
Error: Invalid procedure call or argument
URL: copy of the code in this URL https://github.com/Krinkle/jquery-json/blob/master/src/jquery.json.js

How can I convert my object into JSON string? am I defining my object incorrectly or is there something else that I need to do to get the object converted?

RobG
  • 142,382
  • 31
  • 172
  • 209
Junior
  • 11,602
  • 27
  • 106
  • 212
  • 4
    Use this, https://github.com/douglascrockford/JSON-js then use `JSON.stringify` like normal. – Paul Mar 09 '16 at 00:59
  • IE 8 isn't *that* bad a browser, it's just old. – RobG Mar 09 '16 at 01:02
  • @Paulpro Thank you or the tip. I included this file into my app `https://github.com/douglascrockford/JSON-js/blob/master/json2.js` Then when I try to using JSON.stringify I get an error "Invalid procedure call or argument" Line 314 of the json2.js file. Is the issue with my object and the way I construct it? – Junior Mar 09 '16 at 01:11

0 Answers0