stringify

how to solve (Uncaught TypeError: Converting circular structure to JSON)

爱⌒轻易说出口 提交于 2019-11-30 20:06:39
问题 i have the following object and i am trying to convert it to json object as follows var feeTransactionsArray=[]; $(".editor #newPayTable .mainTr").each(function(){ var feeTransactions={}; var studentDetails={}; var feeCategory={}; studentDetails['studentAdmissionId']=id; feeCategory['feeCatId']=$(this).find('.feeCatId').val(); feeTransactions['studentDetails']=studentDetails; feeTransactions['feeCategory']=feeCategory; feeTransactions['paidOn']=paidDate; feeTransactions['transReceiptNo']

JSON.stringify returns “[object Object]” instead of the contents of the object

社会主义新天地 提交于 2019-11-30 16:54:18
Here I'm creating a JavaScript object and converting it to a JSON string , but JSON.stringify returns "[object Object]" in this case, instead of displaying the contents of the object. How can I work around this problem, so that the JSON string actually contains the contents of the object? var theObject = {name:{firstName:"Mark", lastName:"Bob"}}; alert(JSON.stringify(theObject.toString())); //this alerts "[object Object]" Use alert(JSON.stringify(theObject)); theObject.toString() The .toString() method is culprit. Remove it; and the fiddle shall work: http://jsfiddle.net/XX2sB/1/ JSON

Limit JSON stringification depth

纵饮孤独 提交于 2019-11-30 13:41:21
问题 When stringifying an object using JSON.stringify (or something similar) is there a way to limit the stringification depth, i.e. only go n levels deep into the object tree and ignore everything that comes after that (or better: put placeholders in there, indicating something was left out)? I know that JSON.stringify takes a replacer function of the form function (key, value) but I didn't find a way to get the depth in the original object of the current key-value-pair handed to the replacer

Limit JSON stringification depth

℡╲_俬逩灬. 提交于 2019-11-30 08:02:12
When stringifying an object using JSON.stringify (or something similar) is there a way to limit the stringification depth, i.e. only go n levels deep into the object tree and ignore everything that comes after that (or better: put placeholders in there, indicating something was left out)? I know that JSON.stringify takes a replacer function of the form function (key, value) but I didn't find a way to get the depth in the original object of the current key-value-pair handed to the replacer function. Is there a way to do this with the default JSON.stringify implementation? Or have I reached a

JSON.stringify returns “[object Object]” instead of the contents of the object

試著忘記壹切 提交于 2019-11-30 00:13:56
问题 Here I'm creating a JavaScript object and converting it to a JSON string, but JSON.stringify returns "[object Object]" in this case, instead of displaying the contents of the object. How can I work around this problem, so that the JSON string actually contains the contents of the object? var theObject = {name:{firstName:"Mark", lastName:"Bob"}}; alert(JSON.stringify(theObject.toString())); //this alerts "[object Object]" 回答1: Use alert(JSON.stringify(theObject)); 回答2: theObject.toString() The

JSON String inside a JSON

我怕爱的太早我们不能终老 提交于 2019-11-29 18:28:36
问题 I want to create a JSON string inside a JSON request. Here is my code, Fiddle JS var x = { a: 1, b: 'a sample text', }; var request = { t: JSON.stringify(x), c: 2, r: 'some text' }; console.log(request); Can someone help me how to escape the double quotes? Console Object { t: "{"a":1,"b":"a sample text"}", //This creates a problem, double quotes inside double quotes. c: 2, r: "some text" } Thanks in advance. 回答1: That's just the way the browser console shows you the value of a string, by

Why is json_decode($data, TRUE) converting an array to a string?

限于喜欢 提交于 2019-11-29 15:59:47
JavaScript Code: $.ajax({ type: "POST", url: "postTestingResult.php", data: {data: JSON.stringify(sendData)}, dataType: "json", success: ajaxSuccess, error: ajaxError }); PHP Code $data = json_decode($_POST['data'], TRUE); When I POST a complex data structure to the server, the outermost array is becoming a string. For example, the JavaScript object could be var data = {"apps": [[1,2,3], [4,5,6]]} Using JSON.stringify(data) this becomes "{"apps": "[[1,2,3], [4,5,6]]"}" //As seen via console.log(data) in Chrome console But after doing the json_decode($_POST['data'], TRUE) it becomes array('apps

Replacing values in JSON object

怎甘沉沦 提交于 2019-11-29 05:02:02
I have the following JSON object data returned from my apicontroller : > [ {"id":2,"text":"PROGRAMME","parent":null}, > {"id":3,"text":"STAGE","parent":2}, > {"id":4,"text":"INFRA","parent":2}, > {"id":5,"text":"SYSTEM","parent":3}, > {"id":6,"text":"STOCK","parent":3}, {"id":7,"text":"DPT","parent":3}, > {"id":9,"text":"EXTERNAL","parent":null} ] I want to replace "parent":null with "parent":'"#"' I have tried the code below, but it is only replacing the first occurrence of "parent":null . How can I replace all "parent":null entries? <script> $(document).ready(function () { $.ajax({ url:

Why doesn't JSON.stringify display object properties that are functions?

℡╲_俬逩灬. 提交于 2019-11-29 04:22:25
Why doesn't JSON.stringify() display prop2? var newObj = { prop1: true, prop2: function(){ return "hello"; }, prop3: false }; alert( JSON.stringify( newObj ) ); // prop2 appears to be missing alert( newObj.prop2() ); // prop2 returns "hello" for (var member in newObj) { alert( member + "=" + newObj[member] ); // shows prop1, prop2, prop3 } JSFIDDLE: http://jsfiddle.net/egret230/efGgT/ Eric Because JSON cannot store functions. According to the spec, a value must be one of: (source: json.org ) As a side note, this code will make the functions noticed by JSON.stringify : Function.prototype.toJSON

Why is json_decode($data, TRUE) converting an array to a string?

我们两清 提交于 2019-11-28 09:46:15
问题 JavaScript Code: $.ajax({ type: "POST", url: "postTestingResult.php", data: {data: JSON.stringify(sendData)}, dataType: "json", success: ajaxSuccess, error: ajaxError }); PHP Code $data = json_decode($_POST['data'], TRUE); When I POST a complex data structure to the server, the outermost array is becoming a string. For example, the JavaScript object could be var data = {"apps": [[1,2,3], [4,5,6]]} Using JSON.stringify(data) this becomes "{"apps": "[[1,2,3], [4,5,6]]"}" //As seen via console