0

hii i am trying to convert a javascript object to JSON string . are there any alternative apart from JSON.stringify() ?? cause the method is giving error in IE 7 .... its works perfect in IE8 onwards and other browsers . so just wanna know are there any ways to convert a javascript object such as :

var Schedules = new Object();
Schedules.ProjectTypeID = "abc";
Schedules.ProjectID = "123";
Schedules.ScheduleID = "12345";
Schedules.MilestoneID = "milestone1";

and it should give a json string something like

{"ProjectTypeID":"abc","ProjectID":"123","ScheduleID":"12345","MilestoneID":"milestone1"}

3 Answers 3

1

The reason why you're getting the error in IE7 is because the JSON library that has the .stringify() function is not inherent in IE7's JS model (correct me if I'm mistaken).

So what you want to do is to include the json2.js file that Kon mentioned in his answer above when you're in an IE7 environment (or other incompatible envi).

You could just load it anyway, I guess. I'm pretty sure it won't cause collisions.

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

2 Comments

i tried to load the json2.js but its giving me error in IE as runtime error has occured in IE8 as well as IE7 .... not sure why its occuring like tht
Okie I figured it out ... there was some wrong js file got loaded mistakenly. now its working okie :D .. thanks
1

use the json2.js from this github: https://github.com/douglascrockford/JSON-js

Hope this helps.

Comments

0

Not sure this helps you, but you could just build it in JSON format from the beginning:

var Schedules = {
  ProjectTypeID : "abc",
  ProjectID : "123",
  ScheduleID : "12345",
  MilestoneID : "milestone1"
}

2 Comments

i know i can build it from the begining . but d thing is i dont want that .. i want something equivalent to JSON.stringify() method which directly converts the object to JSON.
Yeah, I figured. You can always rewrite JSON.stringify() yourself. :)

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.