-1

I'm working with a .hta document at the moment, and attempting to import and read from a local JSON file. I've already successfully loaded the file in, and just need to call JSON.parse to turn it into an object. However, even though I have IE11, HTA uses an older Internet Explorer without json2. Even after importing the json2 from the official github in a script tag, I still get an error that JSON is undefined.

I have tried moving my JavaScript to below the body to see if it affects loading times, but that didn't seem to help. I also tried removing and adding the type attribute to the script tag.

var data = '{"name": "Test"}';
var formatted_data = JSON.parse(data);
alert(formatted_data.name);

I expected to get an alert with "Test" as the only text, but instead I get an Internet Explorer dialog reading 'JSON' is undefined. I'm really stumped on this one; usually I can find a simple solution to issues such as this but not in this case.

ogane
  • 5
  • 3
  • Show all the relevant parts of the file in a [mcve]. – Herohtar Aug 16 '19 at 03:54
  • When you talk about json2, are you talking about [this script](https://github.com/douglascrockford/JSON-js/blob/master/json2.js)? Also, are you sure the json2 script tag is *before* your script? – Marco Bonelli Aug 16 '19 at 03:54
  • 1
    Native JSON works in IE starting from version 8, see https://stackoverflow.com/a/19570684/1169519 .. – Teemu Aug 16 '19 at 04:18

1 Answers1

-1

Solved: I moved the type attribute to the end of the imported script tag and followed the recommended json2 library instruction to download a copy. It now imports fine and parses the JS as intended.

ogane
  • 5
  • 3