stringify

Is there a way to JSON.stringify an HTML dom object? [JavaScript]

风流意气都作罢 提交于 2019-12-07 23:58:10
问题 I am trying to load in a external html file and stringify the contents within the body but can't seem to do so without it producing undesired results. Is there even a way to do this? var xhr = new XMLHttpRequest(); function loadFile(){ xhr.open("GET", 'index.html'); xhr.responseType = "document"; xhr.send(); } xhr.onload = function(data) { myData = data; myString = JSON.stringify(myData.srcElement.responseXML.body.children); console.log(myString) //logs: {"0":{},"length":1} } loadFile(); But

Node.js JavaScript-stringify

喜夏-厌秋 提交于 2019-12-07 03:54:00
问题 JSON is not a subset of JavaScript. I need my output to be 100% valid JavaScript; it will be evaluated as such -- i.e., JSON.stringify will not (always) work for my needs. Is there a JavaScript stringifier for Node? As a bonus, it would be nice if it could stringify objects. 回答1: You can use JSON.stringify and afterwards replace the remaining U+2028 and U+2029 characters. As the article linked states, the characters can only occur in the strings, so we can safely replace them by their escaped

Is there a way to JSON.stringify an HTML dom object? [JavaScript]

陌路散爱 提交于 2019-12-06 09:20:48
I am trying to load in a external html file and stringify the contents within the body but can't seem to do so without it producing undesired results. Is there even a way to do this? var xhr = new XMLHttpRequest(); function loadFile(){ xhr.open("GET", 'index.html'); xhr.responseType = "document"; xhr.send(); } xhr.onload = function(data) { myData = data; myString = JSON.stringify(myData.srcElement.responseXML.body.children); console.log(myString) //logs: {"0":{},"length":1} } loadFile(); But what I need it to load is the actual div contents, ex: //log: '<div id ='mydiv'>...</div> What am I

Stringify JavaScript object

ぃ、小莉子 提交于 2019-12-06 00:14:01
问题 I'm looking to stringify an object. I want in output like this {"1":{"valeur":"dalebrun","usager":"experttasp","date":"2013-08-20 16:41:50"}, "2": {"valeur":"test","usager":"experttasp","date":"2013-08-20 16:41:50"}} But I get this {"valeur":"dalebrun","usager":"experttasp","date":"2013-08-20 16:41:50"}, {"valeur":"test","usager":"experttasp","date":"2013-08-20 16:41:50"} What I do var objVal = {}; //value.... var data = {}; //other value.... var object = $.extend({}, objVal, data); //concat

Stringify macro with GNU gfortran

こ雲淡風輕ζ 提交于 2019-12-05 15:25:01
How can I stringify a preprocessor macro with GNU gfortran? I would like to pass a macro definition to GNU gfortran which will then be used as a string in the code. Effectively I would like to do this: program test implicit none character (len=:), allocatable :: astring astring = MYMACRO write (*, *) astring end program test and then build with: gfortran -DMYMACRO=hello test.F90 I tried creating various macro, for example: #define STRINGIFY_(x) #x #define STRINGIFY(x) STRINGIFY_(x) ... astring = STRINGIFY(MYMACRO) but this doesn't work with the gfortran preprocessor. I also tried using a

JSON.stringify in java - android

谁说胖子不能爱 提交于 2019-12-05 11:39:25
问题 Is there any way to perform a JSON.stringify in android? I keep seeing JSON.stringify(JSONObject) all around the web, but I cant find the JSON class in android. Any help? 回答1: JSON.stringify(JSONObject) is a Javascript function and will not be available in Java. If you're using the org.json.* package built in the Android SDK, the equivalent would be to simply call toString() on your JSONObject instance, or the more human-friendly toString(int) . http://developer.android.com/reference/org/json

Node.js JavaScript-stringify

╄→гoц情女王★ 提交于 2019-12-05 08:05:37
JSON is not a subset of JavaScript . I need my output to be 100% valid JavaScript; it will be evaluated as such -- i.e., JSON.stringify will not (always) work for my needs. Is there a JavaScript stringifier for Node? As a bonus, it would be nice if it could stringify objects. You can use JSON.stringify and afterwards replace the remaining U+2028 and U+2029 characters. As the article linked states, the characters can only occur in the strings, so we can safely replace them by their escaped versions without worrying about replacing characters where we should not be replacing them: JSON.stringify

How do I implement a macro that creates a quoted string for _Pragma?

时光总嘲笑我的痴心妄想 提交于 2019-12-05 07:57:52
I want to have a macro that's invoked like this: GCC_WARNING(-Wuninitialized) which expands to code like this: _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") I'm not having luck getting this to work, as the usual tricks of preprocessor joins and stringifying don't seem to apply or I don't know how to apply them here. With the little help of preprocessor magic: #define HELPER0(x) #x #define HELPER1(x) HELPER0(GCC diagnostic ignored x) #define HELPER2(y) HELPER1(#y) #define GCC_WARNING(x) _Pragma(HELPER2(x)) GCC_WARNING(-Wuninitialized) Would it also be acceptable if the macro argument is

JSON.stringify()中文乱码

孤者浪人 提交于 2019-12-04 13:06:44
最近用 json2.js 来做客户端的JSON提交,使用了JSON.stringify()方法,结果发送到服务器端的Json里的中文变成了乱码. 查了一下资料才知道IE8支持原生的JSON对象,自带了JSON.parse与JSON.stringify两个方法。当我使用json2里的Json.stringify方法里IE默认调用了IE8的stringify方法进行了uncode编码,致使传到服务器后中文变成了乱码。 解决办法1: 把Json2.js里的JSON改下名称,改成JSON2,这样调用:JSON2.stringify(); 解决办法2: var answerStr = JSON. stringify ( arr ) ; var o = JSON. parse ( answerStr ) ; eval ( "var answerStr = '" + JSON. stringify ( o ) + "' ;" ) ; 方法1已试,完全可以.方法2未试! 来源: oschina 链接: https://my.oschina.net/u/781254/blog/420564

Stringify JavaScript object

烈酒焚心 提交于 2019-12-04 05:49:27
I'm looking to stringify an object. I want in output like this {"1":{"valeur":"dalebrun","usager":"experttasp","date":"2013-08-20 16:41:50"}, "2": {"valeur":"test","usager":"experttasp","date":"2013-08-20 16:41:50"}} But I get this {"valeur":"dalebrun","usager":"experttasp","date":"2013-08-20 16:41:50"}, {"valeur":"test","usager":"experttasp","date":"2013-08-20 16:41:50"} What I do var objVal = {}; //value.... var data = {}; //other value.... var object = $.extend({}, objVal, data); //concat the object JSON.stringify(object); When you concat the object, you get an array; you want a map with