ExtJS - 语法错误:括号中缺少 )

2024-03-07

我正在编写一些代码来自学 ExtJS 的方法。我对 JSON 也很陌生,所以希望这个问题对你来说很容易回答。我正在尝试从我编写的基本网络服务中检索一些数据should将其结果作为 JSON 返回(因为我是 JSON 新手 - 可能是它被破坏了)。

我得到的错误是

语法错误:缺少 ) 中 括号内的

我从 Web 服务返回的 JSON 是

{
    "rows": [ 
    { 
        "id": "100000", 
        "genre_name": "Action", 
        "sort_order": "100000" 
    }, { 
        "id": "100002", 
        "genre_name": "Comedy", 
        "sort_order": "100002" 
    }, { 
        "id": "100001", 
        "genre_name": "Drama", 
        "sort_order": "100001" 
    }]
}

我的 ExtJS 代码如下。这loadexception回调是我从中检索 JSON 和上面错误的地方

var genres = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
        method: 'POST',
        url: 'http://localhost/extjs_training/Demo_WebService/Utility.asmx/GetGenres',
        failure: function(response, options){
            Ext.get('my_id').dom.innerHTML = 'Load failed: ' + response.status;
        }
    }),
    reader: new Ext.data.JsonReader({
        fields: ['id', 'genre_name'],
        root: 'rows'
    }),
    listeners: {
        loadexception: function (proxy, options, response, e) {
            var result = response.responseText;
            Ext.MessageBox.alert('Load failure', e + " ..... " + result);
        }
    }
});

var loadSuccess = genres.load({
    callback: function(r, options, success){
        Ext.get('my_id').dom.innerHTML = 'Load status: success=' + success;
    }
});

您上面包含的 JSON 是什么actually从电话中返回,或者您期望它应该是什么样子?您包含的字符串看起来很干净,但看起来您也对其进行了格式化。我也不确定“id”之后的空格是否允许。不过,这可能没什么大不了的。

缺少的括号通常表明 JSON 中存在错误。它可能是字符串之前/之后的额外字符。使用 Firebug 检查您返回的内容,并确保其中没有任何多余字符。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ExtJS - 语法错误:括号中缺少 ) 的相关文章

随机推荐