我正在我的ExtJS应用程序中解码一些JSON数据。 它在火狐中工作正常,但在IE中(哎呀,真是令人惊讶)我收到此错误:
SCRIPT438: Object doesn't support property or method 'toSource'
Search.js?_dc=1393865997622, line 194 character 5
我的搜索.js:
var mainresponse = response.toSource(); //Works in FF
response
看起来像这样:
{
"elements":[
{
"element":{
"name":"value 1",
"id":"element 1",
"attributes":[
{
"attrname":"id",
etc...
我的解码是:
var decoded = Ext.decode( mainresponse );
// loop over decoded data
for( var i=0; i < decoded.elements.length; i++ ) {
etc...
有没有快速的解决方案?它发生在浏览器模式 IE9 中。
Object.prototype.toSource()
是非标准的,在IE中不受支持:
非标
此功能是非标准的,不在标准上 跟踪。不要在面向 Web 的生产站点上使用它:它不会 为每个用户工作。两者之间也可能存在很大的不兼容性 实现和行为将来可能会更改。
我已经通过在mainresponse
上使用 JSON 的 stringify
函数而不是response.toSource()
来解决这个问题,然后再对其进行解码。
var mainresponse = JSON.stringify(response);