solve this Javascript error when converting JSON to string

How do I solve this Javascript error when converting JSON to string?javascript

This q come from stackoverflow see:
http://stackoverflow.com/questions/4954242/how-do-i-solve-this-javascript-error-when-converting-json-to-stringhtml

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<v.length;i++){
            var temparr = new Object();
            temparr.id = v[i].id;
            temparr.text = v[i].text;
            arr1[i] = temparr;
        }
        $("#tags").val(JSON.stringify(arr1));

这段代码大致背景就是从select2中获取到的结果实际上是一个对象数组中嵌套对象数组。
可是经过JSON.stringify来说对象转换成json有的时候回提示错误:Uncaught TypeError: Converting circular structure to JSON,没错,这个错误就是指针循环了致使的。java

由于从select2中或得的对象里面包含了大量select2的api信息,有的信息存在指针循环的现象,能够经过网上一些人的办法经过替换这样问题的对象,也能够采用个人办法,就是将本身须要的信息提取出来,一目了然,不会再发生前面提到的错误。json

用stackoverflow上面最佳答案就是:api

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.this

以上google

Thank you!