Reputation: 2682
In my asp.Net application (MVC 3) in a View I am working with some jquery control. I got json
{
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
how can I get values of attrubutes?
Upvotes: 0
Views: 67
Reputation: 2078
if you take
var data = {
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
If the properties of attributes DONT change you can use data.attributes.url
as @furqan said.
But if your properties CAN change you can just iterate through the properties like
for(x in data.attrubutes)
{
//do some specific code for x which will be the NAME of the attribute.
//by calling data.attributes[x] for the value.
}
Upvotes: 1
Reputation: 14672
I think you need
var json = {
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
json.attributes.url
for example.
Upvotes: 1
Reputation: 3794
You do objectName[attributename]
or objectName.attributename
for example
var test = {
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
test.text
Will return the value
Upvotes: 0