Javascript -.toJSON

I'm new to JSON, and so I'm not sure what that means $.toJSON(params).

Please explain what this does.

+5
source share
3 answers

It could be a jQuery plugin

var myObj = {};
myObj.propA = "a";
myObj.propB = "b";
myObj.propC = "c";
var jsonString = $.toJSON(myObj); // same as jQuery.toJSON(myObj)
// output:  '{ "propA" : "a", "propB" : "b", "propC" : "c" }'
+11
source

See: http://www.json.org/js.html

The JSON binder moves in the opposite direction, converting JavaScript data structures to JSON text. JSON does not support circular data structures, so be careful not to cast circular structures to string JSON.

var myJSONText = JSON.stringify(myObject, replacer);

stringify , toJSON, . JSON.

. , JSON.

replacer. toJSON ( ) . , , . .

, $.toJSON(), "", " JSON" $

+5

It passes a variable paramsas an argument to a method with a name toJSONattached to an object stored in a ( uselessly named ) variable $.

Based on the name, it will probably convert the contents of the variable paramsto a string formatted according to the specification

+1
source

All Articles