0

我必须像这样使用json文件:

({"weather":{"city":"Paris", "country":"France"}})

我将 JsonStore 编写为:

root : "weather",
fields : ['city', 'country']

我无法像这样访问它们:

myStore.on('load', function(store, records, options) {
alert(records[0].get('city'));
}

但是我怎样才能访问它们,因为我的 json 文件没有括号

另一种情况是当我想访问这样的东西时:

({"data":{"weather":[{ "city" : "Paris", "country" : [{"value" : "France"}] }]}})

我将根定义为“data.weather”

fields:['city','country']

但我无法访问国家/地区的价值

请描述 json 文件解析或者有没有办法将 json 文件加载为纯文本/文本?

4

1 回答 1

1

我对 extjs 不熟悉,但我会试一试,因为它似乎不是非常特定于框架。

您无法索引,records因为您的 JSON 中没有数组。我想如果你用过records.get('city'),你会得到Paris

于 2011-08-13T03:35:25.810 回答