我正在努力找出为什么在我正在开发的应用程序中会发生以下情况:
因此,我读取了一个JSON文件,希望在其中读取并保存他在localStorage上的内容,在chrome应用程序中,它是chrome.storage.local
因此,我从一个json文件中获得了以下内容:
{
"schedule": {
"id": "416a18d6-7e42-4f8a-ac24-e902abe76f39",
"name": "blabla",
"updatedOn": "2013-09-08T16:34:41.000Z",
"etag": "esxrdctfvygbuhnij5464df7g8hu",
"applications": [
{
"id": "app001",
"type": "text/html",
"src": "http://www.google.com"
},
{
"id": "app002",
"type": "text/html",
"src": "http://www.stackoverflow.com"
}
],
"normalContent": [
{
"layout_id": "layout001",
"layout_name": "layout1",
"layout_dur": "indefinite",
"regions": [
{
"region_id": "region001",
"region_name": "regiao1",
"left": "0",
"top": "0",
"width": "0.5",
"height": "1",
"minWidth": "0",
"minHeight": "0",
"scheduleItem": "container",
"limitCycle": "1",
"selector": "seq",
"containerList": [
{
"cid": "app001",
"dur": "25"
},
{
"cid": "app002",
"dur": "15"
}
]
},
{
"region_id": "region002",
"region_name": "regiao2",
"left": "0.5",
"top": "0",
"width": "0.5",
"height": "1",
"minWidth": "0",
"minHeight": "0",
"scheduleItem": "container",
"limitCycle": "1",
"selector": "seq",
"containerList": [
{
"cid": "app002",
"dur": "15"
},
{
"cid": "app001",
"dur": "15"
}
]
}
]
}
]
}
}因此,我得到了这个,然后我使用以下命令将内容保存在存储中:
chrome.storage.local.set({playerSchedule:this.schedule}, function(){
console.log('saved!')
});稍后,当我使用以下命令读取存储的内容时:
chrome.storage.local.get(["playerSchedule", "playerScheduleType"], function (res) {
self.currentSchedule = res.playerSchedule;
self.scheduleType = res.playerScheduleType;
});这是我得到的:
{
"schedule": {
"applications": [
{
"id": "app001",
"type": "text/html",
"src": "http://www.google.com"
},
{
"id": "app002",
"type": "text/html",
"src": "http://www.stackoverflow.com"
}
],
"etag": "esxrdctfvygbuhnij5464df7g8hu",
"id": "416a18d6-7e42-4f8a-ac24-e902abe76f39",
"name": "blabla",
"normalContent": [
{
"layout_dur": "indefinite",
"layout_id": "layout001",
"layout_name": "layout1",
"regions": [
{
...
"containerList": [
]
},
{
...
"containerList": [
]
}
]
}
],
"updatedOn": "2013-09-08T16:34:41.000Z"
}
}正如您所看到的,我阅读的内容是按字母顺序排列的,而containerList中的内容是空的。为什么会发生这种情况呢?我通过将对象转换为字符串并将其存储来解决了这个问题,但我想知道为什么将对象另存为对象时,我会将其作为对象读取,或者是我遗漏了什么?
提前谢谢。
发布于 2013-09-12 00:42:01
这可能是http://code.google.com/p/chromium/issues/detail?id=277647。Chrome 31的修复工作正在进行中。
https://stackoverflow.com/questions/18723922
复制相似问题