parabol
parabol

Reputation: 63

problem in accessing json parameters

I have to use json file like this:

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

I write a JsonStore as:

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

I cant access them like:

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

but how can I access them because my json file doesn't have bracket

another case is when I want to access somthing like this:

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

I define root as "data.weather"

fields:['city','country']

but I cant access value of country

please describe json file parsing or is there a way to load json file as plain/text?

Upvotes: 0

Views: 281

Answers (1)

no.good.at.coding
no.good.at.coding

Reputation: 20371

I'm not familiar with extjs but I'll give this a shot since it doesn't seem to be very specific to the framework.

You can't index into records because you don't have an array in your JSON. I'd imagine if you used records.get('city'), you'd get Paris.

Upvotes: 1

Related Questions