从json文件填充集合

Raj*_*ian 7 json backbone.js

我想从json文件填充一个集合,该文件除了数据项数组外还有其他数据.我开始知道集合上的解析函数应该用于返回数据项的数组,但是我的集合没有从json文件中填充.当我在firebug中使用解析方法保留断点时,控件根本就不会出现.

这是我的代码

        var m1 = Backbone.Model.extend({                
                title:'Title1',
                tag:'html',
                date: 'Today'
        })
        cll = Backbone.Collection.extend({
            url:'/combodata.json?uu',
            model:m1,
            parse:function(res){                    
                return res.items;
            }
        });

        ci = new cll();
        ci.fetch();
Run Code Online (Sandbox Code Playgroud)

json响应将是这样的

{
'identifier': 'title',
items:[
    {title:'A', tag:"htmlcss", date:'today'},
    {title:'AA', tag:"htmlcss", date:'today'},
    {title:'B', tag:"htmlcss", date:'today'},
    {title:'C', tag:"htmlcss1", date:'today'}
]}
Run Code Online (Sandbox Code Playgroud)

请指出我错在哪里.

May*_*ura 8

不是JSON的专家,但我尝试在jsonlint.com验证您的JSON .它在第2行失败了

Parse error on line 1:
{    'identifier': 'title
-----^
Expecting 'STRING', '}'
Run Code Online (Sandbox Code Playgroud)

请验证您的JSON是否有效.

只是检查其他网站为您JSON验证http://jsonformatter.curiousconcept.com/,似乎,该字符串应该标识符用双引号代替单引号使用.用双引号替换单引号可能会有所帮助.