为什么此 JSON“无效?”
此 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拥有的是有效的 JSON,但它不是有效的 JSON P
您需要更改
为
What you have is valid JSON, but it's not valid JSON P
You need to change
to