【问题标题】:Why is this JSON "invalid?"为什么这个 JSON “无效”?
【发布时间】:2012-02-06 02:58:05
【问题描述】:

此 JSON 通过 jsonlint 验证。然而 Firefox 和 Chrome 拒绝它:

{
    "messages": [
        {
            "subject": "One"
        },
        {
            "subject": "Two"
        },
        {
            "subject": "Three"
        }
    ],
    "totalResults": 10
}

错误消息是“消息”上的“无效标签”。

这是它的加载方式:

var store = Ext.create('Ext.data.Store', {
    model: 'MyModel',
    autoLoad: true,
    pageSize: 3,
    proxy: {
        type: 'jsonp',
        url: 'http://localhost:8080/document-viewer-1.0/testdata.json',
        reader: {
            root: 'messages',
            totalProperty: 'totalResults'
        }
    }
});

回答

这是我自己的愚蠢错误。我没有将 JSONP 回调名称放在 JSON 文件结构周围。

【问题讨论】:

标签: javascript json validation syntax-error jsonlint


【解决方案1】:

你拥有的是有效的 JSON,但它不是有效的 JSON P

你需要改变

type: 'jsonp',

type: 'json',

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多