摘要:這個問題已經提問者已經解決,雖然解決的辦法不盡人意,但是他采納了公眾贊同的答案。解決轉換時指針循環問題這段代碼大體背景就是從中獲取到的結果其實是一個對象數組中嵌套對象數組。用上面最佳答案就是以上
How do I solve this Javascript error when converting JSON to string?
This q come from stackoverflow see:
http://stackoverflow.com/questions/4954242/how-do-i-solve-this-javascript-error-when-converting-json-to-string
Uncaught TypeError: Converting circular structure to JSON The object I"m trying to stringify is this (I logged it in javascript console): Object GsearchResultClass: "GlocalSearch" accuracy: "8" addressLines: Array[2] city: "Cupertino" content: "" country: "United States" ddUrl: "http://www.google.com/maps?source=uds&daddr=10825+North+Wolfe+Road,+Cupertino,+CA+(Southland+Flavor+…" ddUrlFromHere: "http://www.google.com/maps?source=uds&saddr=10825+North+Wolfe+Road,+Cupertino,+CA+(Southland+Flavor+…" ddUrlToHere: "http://www.google.com/maps?source=uds&daddr=10825+North+Wolfe+Road,+Cupertino,+CA+(Southland+Flavor+…" html: HTMLDivElement lat: "37.335405" listingType: "local" lng: "-122.015386" maxAge: 604800 phoneNumbers: Array[1] region: "CA" staticMapUrl: "http://maps.google.com/maps/api/staticmap?maptype=roadmap&format=gif&sensor=false&size=150x100&zoom=…" streetAddress: "10825 North Wolfe Road" title: "Southland Flavor Cafe" titleNoFormatting: "Southland Flavor Cafe" url: "http://www.google.com/maps/place?source=uds&q=stinky&cid=9384294304761453216" viewportmode: "computed" __proto__: Object And I"m doing it like this: JSON.stringify(theobject);
這個問題已經提問者已經解決,雖然解決的辦法不盡人意,但是他采納了公眾贊同的答案。 作者也在這個問題上花了一部分時間,下面闡述一下我的解決方法。
var v =$("#tagse").select2("data"); //解決轉換時指針循環問題 var arr1 = []; for(var i=0;i這段代碼大體背景就是從select2中獲取到的結果其實是一個對象數組中嵌套對象數組。
但是通過JSON.stringify來講對象轉換成json有的時候回提示錯誤:Uncaught TypeError: Converting circular structure to JSON,沒錯,這個錯誤就是指針循環了導致的。因為從select2中或得的對象里面包含了大量select2的api信息,有的信息存在指針循環的現象,可以通過網上一些人的辦法通過替換這樣問題的對象,也可以采用我的辦法,就是將自己需要的信息提取出來,一目了然,不會再發生前面提到的錯誤。
用stackoverflow上面最佳答案就是:
An object is referencing itself somewhere; hence the message "circular structure." I suspect it might be in the HTMLDivElement. Are you using this only for debugging purposes or do you actually want to do something meaningful with this JSON? If you"re just using it for debugging, most modern JavaScript debuggers will let you just log an object to the console. If you"re actually trying to do something with the data, you should pull out only the things you need from this object and put them into a new trimmed down object that you can pass to JSON.stringify. This object looks like it came from a Google API and has lots of extra data in it.
If you don"t mind destructively modifying the object, try selectively nulling out suspicious fields and see if JSON.stringify will accept the object. At least that way you"ll know what"s causing it. Note that if you do this you may end up breaking the object for any future uses.
以上
Thank you!
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/78638.html
Memory Leak (內存泄漏) Origin: https://aleen42.gitbooks.io/p...Date: Sep, 10th, 2016 In the process of developing front-end application, like web application, memory leak means that a space created before...
現在流行的axios庫不支持jsonp,因此這里推薦一個jsonp庫,簡單易用。以下是介紹: Easy JSONP A minimal and lightweight JSONP implementation which is used to be a kind of cross domain solutions. Features Implement JSONP request from th...
摘要:標簽前端作者更多文章個人網站 Learning Notes - Understanding the Weird Parts of JavaScript 標簽 : 前端 JavaScript [TOC] The learning notes of the MOOC JavaScript: Understanding the Weird Parts on Udemy,including...
摘要:為了避免不同項目之間進行復制粘貼,可以將這些常用的函數封裝到一起并發布包。目前所包含模塊已達三百個,基本可以滿足前端的日常工發需求。二使用打包工具該項目自帶打包工具,可以通過配置文件或命令行掃描源碼自動生成項目專用的工具庫。 前言 在業務開發過程中,我們經常會重復使用日期格式化、cookie 操作、模板、瀏覽器判斷、類型判斷等功能。為了避免不同項目之間進行復制粘貼,可以將這些常用的函數...
摘要:歡迎來我的專欄查看系列文章。主要來看函數函數返回值有兩個,其中就是發送函數了,一步一步,發送下來,無需多說明。參考源碼分析系列整體結構源碼分析系列總結觸碰異步詳解本文在上的源碼地址,歡迎來。 歡迎來我的專欄查看系列文章。 關于 ajax,東西太多了,我本來想避開 ajax,避而不提,但覺得 ajax 這么多內容,不說又少點什么,就簡單點來介紹吧,加上最近準備內推面試的時候,看了不少 a...
閱讀 3223·2021-09-09 11:39
閱讀 1228·2021-09-09 09:33
閱讀 1127·2019-08-30 15:43
閱讀 546·2019-08-29 14:08
閱讀 1733·2019-08-26 13:49
閱讀 2376·2019-08-26 10:09
閱讀 1545·2019-08-23 17:13
閱讀 2283·2019-08-23 12:57