stringify

How to stringify event object?

柔情痞子 提交于 2019-12-17 02:47:11
问题 JSON.stringify(eventObject); gives: TypeError: Converting circular structure to JSON dojox.json.ref.toJson(eventObject); gives: TypeError: Accessing selectionEnd on an input element that cannot have a selection. Is there some library/code ready to use to accomplish it ? 回答1: You won't be able to serialize an event object with JSON.stringify, because an event object contains references to DOM nodes, and the DOM has circular references all over the place (e.g. child/parent relationships). JSON

Excluding object properties while json-stringifying array object

无人久伴 提交于 2019-12-14 01:45:46
问题 hey I have a array object something like this [{ public: "public", private: "private", [{ properties: {... }, instance: {..... } }, {... }, {... }] }, {... }, {.... }] Here the outer most array contains object of class A, which has a some public props, some private porps and it also contains an array which contains object of class B, which also contains some public and private fields. so basically this is my hierarchy array = [A1,A2,A3,A4,....]//object of A var A = function(){ var Const =

What does 'symbol-keyed' mean in 'JSON.stringify'

喜欢而已 提交于 2019-12-13 18:06:57
问题 There is a Object generated by NodeJS, it looks like this when I use console.log: { dataValues: { a: 1, b: 2 }, fn1: function(){}, fn2: function(){} } when I use JSON.stringify, it return this string: {"a":1,"b":1} I checked the mozilla developer center and found this: All symbol-keyed properties will be completely ignored, even when using the replacer function. I think the 'dataValues' must be the 'symbol-keyed' property, but what does 'symbol-keyed' mean? btw, I use the sequelizejs ORM lib

Angular4 - why does custom toJSON() only get called on new objects?

寵の児 提交于 2019-12-13 08:44:59
问题 I have this code. Notice that the serialization is simply renaming the template_items property to template_items_attributes: export class Template { constructor( ) {} public id: string public account_id: string public name: string public title: string public info: string public template_items: Array<TemplateItem> toJSON(): ITemplateSerialized { return { id: this.id, account_id: this.account_id, name: this.name, title: this.title, info: this.info, template_items_attributes: this.template_items

sequential calls of methods asynchronously

风格不统一 提交于 2019-12-12 15:20:02
问题 I have a list of methods I am calling in a method, as follows: this.doOneThing(); someOtherObject.doASecondThing(); this.doSomethingElse(); When this is synchronous, they are executed one after the other, which is required. But now I have someOtherObject.doASecondThing() as asynchronous, and I might turn doOneThing as async too. I could use a callback and call that.doSomethingElse from inside the callback: var that = this; this.doOneThing( function () { someOtherObject.doASecondThing(function

Write a Macro to stringify the contents of a struct

牧云@^-^@ 提交于 2019-12-12 06:28:36
问题 I am trying to write a macro to expand the contents of a struct: struct Str { int a; float f; char *c; }; Str s = {123, 456.789f, "AString"}; #define STRINGIFY_STR(x) ... // Macro to stringify x which is an instance of Str printf("%s", STRINGIFY_STR(s)); desired output: [a: 123, f:456.789, c:AString] Is it possible to write a macro that does this? If it is, then how? 回答1: Is there a reason you want to do this as a macro? You should write a function to perform this action instead of using the

Merging two json (deep nested)

笑着哭i 提交于 2019-12-12 01:39:38
问题 I tried to merge two json both with $.extend and $.merge but no success. I also tried to attach it like this: data: JSON.stringify({"data" : [ {term: request.term}, jsontag ]}), Here's my setup: autocomplete: ({ source: function (request, response) { var tags = $('#input-newsearch-2').val(); var jsonfied = { tags: tags.replace(/,$/, "").split(",").map(function (tag) { return { tag: tag }; }) }; var jsontag = JSON.stringify(jsonfied); var jsonterm = JSON.stringify({ term: request.term }); /

Angular - TypeError: Converting circular structure to JSON

荒凉一梦 提交于 2019-12-11 23:21:39
问题 I'm getting this error at angular service's map method but my returned datas doesn't seem to contain any circular reference, here is my json object: [{"id":14, "sender": {"id":20,"email":"p.martelliere@gmail.com","username":"test5","roles": ["ROLE_USER"],"status":"active","note":"0","points":0, "devices":[],"job":"Caisse","showJob":false,"notificationsActivated":true, "connected":true,"tokenConfirm":"","birthDate":[] },"receiver": {"id":12,"email":"test2@yopmail.com","username":"test2",

Use JSON.stringify and JSON.parse in resteasy

放肆的年华 提交于 2019-12-11 14:48:43
问题 I need to use JSON.stringify and JSON.parse in a java class that contains resteasy services to exchange information with a Jquery script. Which library should import the java class or what should I do ?, because in the script itself let me do it by default. Thank you very much. 回答1: So from my understanding you want to be able to serialize and deserialize JSON to and from Java object, as that's what JSON.stringify and JSON.parse does for Javascript. To be able to handle that, we need a

return Json.Stringfy result

核能气质少年 提交于 2019-12-11 13:39:54
问题 I have this piece of code : $.getJSON('http://myjsonurl', function(json){console.log(JSON.stringify(json.columns)); }); This returns in the console all I need from my json response. My aim is to get this value into a function so that I can call it in another place. (For example : "columns" : getColumns(); So I am making a function like this : function getColumns() { $.getJSON('http://myjsonurl', function(json){return JSON.stringify(json.columns); }); } console.log(getColumns()); // and then