gpt4 book ai didi

json - 从 json 文件填充集合

转载 作者:行者123 更新时间:2023-12-04 11:43:35 25 4
gpt4 key购买 nike

我想从一个 json 文件填充一个集合,该文件除了数据项数组之外还有其他数据。我开始知道应该使用集合上的解析函数来返回数据项数组,但是我的集合没有从 json 文件中填充。当我在 firebug 中的 parse 方法处保留断点时,控件根本没有到达那里。

这是我的代码

        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();

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'}
]}

请指出我错在哪里。

最佳答案

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

Parse error on line 1:
{ 'identifier': 'title
-----^
Expecting 'STRING', '}'

请验证您的 JSON 是否有效。

刚刚检查了另一个站点以进行 JSON 验证 http://jsonformatter.curiousconcept.com/看起来,字符串标识符应该与双引号而不是单引号一起使用。用双引号替换单引号可能会有所帮助。

关于json - 从 json 文件填充集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6744569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com