在我的asp.Net应用程序(MVC 3)中,我使用了一些jQuery控件。我得到json从json格式对象中获取值
{
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
如何获取attrubutes的值?
在我的asp.Net应用程序(MVC 3)中,我使用了一些jQuery控件。我得到json从json格式对象中获取值
{
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
如何获取attrubutes的值?
你做objectName[attributename]
或objectName.attributename
例如
var test = {
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
test.text
将返回值
我想你需要
var json = {
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
json.attributes.url
例如,。
谢谢,但它不起作用,elemet有属性,有价值的关键url,但这是行不通的 – revolutionkpi 2012-08-16 11:48:41
我刚刚尝试过它,它似乎很好,从我的调试器,\t \t json.attributes.url \t“/ demo/book/abc“\t String。如果你想提供更多的代码来给出一些上下文,请做。 – 2012-08-16 12:10:06
,如果你把
var data = {
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
如果属性的属性,不改变这你可以用data.attributes.url
作为@furqan说。
但是如果你的属性也会随之改变,你可以通过属性只是想迭代像
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.
}
试'data.attributes.url',其中数据是你的JSON对象。 – 2012-08-16 10:04:13