Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have created a javascript object. In my app I'm setting values to the different properties of that object.

I have a WCF service that I want to pass the parameter object to. From what I understand I should be able to use JSON.stringify() to do this.

So if my WCF service has a Person object parameter defined as:
C#
public class Person
{
   public string FirstName;
   public string LastName;
}

and I have created a Person javascript object as:
JavaScript
var person =
{
    "FirstName":"Jack",
    "LastName":"Johnson"
};

then I should be able to use: JSON.stringify(person) in my javascript in order to generate a JSON parameter I can pass through a jquery ajax call to my WCF service.

The problem is when I call JSON.stringify() in my code I get a js error during runtime: "Microsoft JScript runtime error: 'JSON' is undefined."

So what do I need to do to be able to use JSON.stringify? I read a post saying that stringify may not be supported by jquery 1.4.1 and I added a reference to Crockford's json2.js file but I'm still getting the error. Can someone please shed some light on this?
Posted
Updated 24-Jun-11 9:39am
v2
Comments
Sergey Alexandrovich Kryukov 24-Jun-11 13:40pm    
Tag it! Platform? Language? (Don't tell us it's in text; before reading the text anyone needs to see the tags). Use "Improve question".
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900