访问json参数的问题

时间:2011-08-13 03:28:15

标签: json extjs jsonstore

我必须像这样使用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"}] }]}})

我将root定义为“data.weather”

fields:['city','country']

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

请描述json文件解析或有没有办法将json文件加载为plain / text?

1 个答案:

答案 0 :(得分:1)

我对extjs并不熟悉,但是我会给它一个机会,因为它似乎不是特定于框架。

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

相关问题