Jump to content
  • Advertisement
Sign in to follow this  
Black Knight

[web] JSON file and IE

This topic is 2809 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I've downloaded this file :
http://www.json.org/json2.js

Added it to my index page before my own javascript file:
<script type="text/javascript" src="json.js"></script>

Then i try to load a txt file like so :


var getXMLHttpRequest = function()
{
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest();
}
else {
try {
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch(ex) {
return null;
}
}
};


var loadJSON = function(url)
{
var xmlHttp = getXMLHttpRequest();

if (xmlHttp != null)
{
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
JSON.parse(xmlHttp.responseText);
}
};


xmlHttp.send(null);

return xmlHttp.responseText;

}
else
alert("Your browser does not support XML HTTP.");
};





The content of the text file is a simple JSON object which loads fine in Firefox, but in IE i get an error pointing to line JSON.parse(xmlHttp.responseText);

Anyone know what's wrong?

Share this post


Link to post
Share on other sites
Advertisement
Looks like it was a comma in the json file, running it through JSON validator brought it up.

{
"name": "Black knight",

"images": {
"image1" : "assets/1.jpg",
"image2" : "assets/2.jpg",
"image3" : "assets/3.jpg",
"image4" : "assets/4.jpg",
}
}



The last comma was breaking things in IE.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!