azamsharp
azamsharp

Reputation: 20094

Converting JavaScript Object to JSON String Using jQuery

I am using the following code to convert js object to json but not seems to be working:

 var params = new Object(); 
      params.fileCode = $(this).val(); 

      var something = jQuery.stringify(params); 

UPDATE 1:

I updated the code to this but still no success:

 var params = new Object(); 
      params.fileCode = $(this).val(); 

      var p = $.toJSON(params); // object does not support this property or method 

      var s = JSON.stringify(params); // JSON is not defined

Upvotes: 2

Views: 9496

Answers (1)

Rob W
Rob W

Reputation: 349252

jQuery does not support the stringify method. Use JSON.stringify instead.

For backwards compability, you can include the json2.js file from https://github.com/douglascrockford/JSON-js.

Upvotes: 6

Related Questions