stringify

Javascript: stringify object (including members of type function)

懵懂的女人 提交于 2019-11-26 13:58:04
问题 I'm looking for a solution to serialize (and unserialize) Javascript objects to a string across browsers, including members of the object that happen to be functions. A typical object will look like this: { color: 'red', doSomething: function (arg) { alert('Do someting called with ' + arg); } } doSomething() will only contain local variables (no need to also serialize the calling context!). JSON.stringify() will ignore the 'doSomething' member because it's a function. I known the toSource()

Convert javascript object or array to json for ajax data

孤者浪人 提交于 2019-11-26 13:05:26
So I'm creating an array with element information. I loop through all elements and save the index. For some reason I cannot convert this array to a json object! This is my array loop: var display = Array(); $('.thread_child').each(function(index, value){ display[index]="none"; if($(this).is(":visible")){ display[index]="block"; } }); I try to turn it into a JSON object by: data = JSON.stringify(display); It doesn't seem to send the proper JSON format! If I hand code it like this, it works and sends information: data = {"0":"none","1":"block","2":"none","3":"block","4":"block","5":"block","6":

Stringify (convert to JSON) a JavaScript object with circular reference

江枫思渺然 提交于 2019-11-26 11:15:14
I've got a JavaScript object definition which contains a circular reference: it has a property that references the parent object. It also has functions that I don't want to be passed through to the server. How would I serialize and deserialize these objects? I've read that the best method to do this is to use Douglas Crockford's stringify. However, I'm getting the following error in Chrome: TypeError: Converting circular structure to JSON The code: function finger(xid, xparent){ this.id = xid; this.xparent; //other attributes } function arm(xid, xparent){ this.id = xid; this.parent = xparent;

Serializing object that contains cyclic object value

寵の児 提交于 2019-11-26 06:33:42
I have an object (parse tree) that contains child nodes which are references to other nodes. I'd like to serialize this object, using JSON.stringify() , but I get : TypeError: cyclic object value because of the constructs I mentioned. How could I work around this? It does not matter to me whether these references to other nodes are represented or not in the serialized object. On the other hand, removing these properties from the object when they are being created seems tedious and I wouldn't want to make changes to the parser (narcissus). Use the second parameter of stringify , the replacer

Stringify (convert to JSON) a JavaScript object with circular reference

梦想与她 提交于 2019-11-26 02:09:03
问题 I\'ve got a JavaScript object definition which contains a circular reference: it has a property that references the parent object. It also has functions that I don\'t want to be passed through to the server. How would I serialize and deserialize these objects? I\'ve read that the best method to do this is to use Douglas Crockford\'s stringify. However, I\'m getting the following error in Chrome: TypeError: Converting circular structure to JSON The code: function finger(xid, xparent){ this.id

Serializing object that contains cyclic object value

笑着哭i 提交于 2019-11-26 00:53:10
问题 I have an object (parse tree) that contains child nodes which are references to other nodes. I\'d like to serialize this object, using JSON.stringify() , but I get TypeError: cyclic object value because of the constructs I mentioned. How could I work around this? It does not matter to me whether these references to other nodes are represented or not in the serialized object. On the other hand, removing these properties from the object when they are being created seems tedious and I wouldn\'t