为什么此 JSON“无效?”

发布于 2024-12-25 21:08:49 字数 807 浏览 4 评论 0原文

此 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 文件结构周围。

This JSON passes jsonlint validation. Yet Firefox and Chrome reject it:

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

The error message is "invalid label" on "messages."

This is how it is being loaded:

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'
        }
    }
});

Answer:

It was my own stupid mistake. I didn't put the JSONP callback name around the JSON file structure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素染倾城色 2025-01-01 21:08:49

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

您需要更改

type: 'jsonp',

type: 'json',

What you have is valid JSON, but it's not valid JSON P

You need to change

type: 'jsonp',

to

type: 'json',
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文