成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

solve this Javascript error when converting JSON t

alphahans / 392人閱讀

摘要:這個問題已經(jīng)提問者已經(jīng)解決,雖然解決的辦法不盡人意,但是他采納了公眾贊同的答案。解決轉(zhuǎn)換時指針循環(huán)問題這段代碼大體背景就是從中獲取到的結(jié)果其實是一個對象數(shù)組中嵌套對象數(shù)組。用上面最佳答案就是以上

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);
 這個問題已經(jīng)提問者已經(jīng)解決,雖然解決的辦法不盡人意,但是他采納了公眾贊同的答案。
 
 作者也在這個問題上花了一部分時間,下面闡述一下我的解決方法。
 
  var v =$("#tagse").select2("data");

        //解決轉(zhuǎn)換時指針循環(huán)問題
        var arr1 = [];
        for(var i=0;i

這段代碼大體背景就是從select2中獲取到的結(jié)果其實是一個對象數(shù)組中嵌套對象數(shù)組。
但是通過JSON.stringify來講對象轉(zhuǎn)換成json有的時候回提示錯誤:Uncaught TypeError: Converting circular structure to JSON,沒錯,這個錯誤就是指針循環(huán)了導(dǎo)致的。

因為從select2中或得的對象里面包含了大量select2的api信息,有的信息存在指針循環(huán)的現(xiàn)象,可以通過網(wǎng)上一些人的辦法通過替換這樣問題的對象,也可以采用我的辦法,就是將自己需要的信息提取出來,一目了然,不會再發(fā)生前面提到的錯誤。

用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!

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/78638.html

相關(guān)文章

  • Memory Leak in JavaScript

    Memory Leak (內(nèi)存泄漏) 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...

    LeviDing 評論0 收藏0
  • 簡潔易用的基于Promise的jsonp庫easy-jsonp,了解下

    現(xiàn)在流行的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...

    Dr_Noooo 評論0 收藏0
  • Learning Notes - Understanding the Weird Parts of

    摘要:標簽前端作者更多文章個人網(wǎng)站 Learning Notes - Understanding the Weird Parts of JavaScript 標簽 : 前端 JavaScript [TOC] The learning notes of the MOOC JavaScript: Understanding the Weird Parts on Udemy,including...

    inapt 評論0 收藏0
  • Licia:最全最實用的 JavaScript 工具庫

    摘要:為了避免不同項目之間進行復(fù)制粘貼,可以將這些常用的函數(shù)封裝到一起并發(fā)布包。目前所包含模塊已達三百個,基本可以滿足前端的日常工發(fā)需求。二使用打包工具該項目自帶打包工具,可以通過配置文件或命令行掃描源碼自動生成項目專用的工具庫。 前言 在業(yè)務(wù)開發(fā)過程中,我們經(jīng)常會重復(fù)使用日期格式化、cookie 操作、模板、瀏覽器判斷、類型判斷等功能。為了避免不同項目之間進行復(fù)制粘貼,可以將這些常用的函數(shù)...

    luxixing 評論0 收藏0
  • jQuery 源碼系列(十九)ajax 的相關(guān)操作

    摘要:歡迎來我的專欄查看系列文章。主要來看函數(shù)函數(shù)返回值有兩個,其中就是發(fā)送函數(shù)了,一步一步,發(fā)送下來,無需多說明。參考源碼分析系列整體結(jié)構(gòu)源碼分析系列總結(jié)觸碰異步詳解本文在上的源碼地址,歡迎來。 歡迎來我的專欄查看系列文章。 關(guān)于 ajax,東西太多了,我本來想避開 ajax,避而不提,但覺得 ajax 這么多內(nèi)容,不說又少點什么,就簡單點來介紹吧,加上最近準備內(nèi)推面試的時候,看了不少 a...

    Dean 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<