【发布时间】:2014-04-15 09:37:20
【问题描述】:
Sencha Touch Web 应用从 REST Web 服务提交的 JSON 加载商店。对于其他技术要求,JSON 不是标准的(但仍然有效)并遵循以下模式:
{
"101": {
"id": "101",
"title": "title 101",
"description": "description 101",
"order": "20",
"thumb": {
"id": "10101",
"uri": "http://linktothumb.jpg"
},
"parent": "0",
"cType": "5"
},
"102": {
"id": "102",
"title": "title 102",
"description": "description 102",
"order": "59",
"thumb": {
"id": "10102",
"uri": "http://linktothumb.jpg"
},
"parent": "101",
"cType": "5"
}
}
不幸的是,当我执行 myStore.load() 时,ST 无法解析 JSON,并且数据不会添加到存储中。但如果 JSON 响应遵循以下模式,它会起作用:
[
{
"id": "101",
"title": "title 101",
"description": "description 101"
"thumb": {
"id": "10101",
"uri": "http://linktothumb.jpg"
},
"parent": "0"
},
{
"id": "102",
"title": "title 102",
"description": "description 102"
"thumb": {
"id": "10102",
"uri": "http://linktothumb.jpg"
},
"parent": "101"
}
]
我无法更改 JSON 的格式,所以我需要找到一种方法让它与这个响应一起工作。是否可以向 ST 的 JSON 阅读器添加参数,或者是否可以手动解析 JSON 响应?如果是,如何?
这是我商店的代理:
proxy: {
type:'rest',
useDefaultXhrHeader : false,
headers: {
'Accept': 'application/json'
},
reader: {
type:'json'
}
}
【问题讨论】:
标签: json extjs sencha-touch sencha-touch-2