C# 从json格式对象获取值
在我的asp.Net应用程序(MVC3)视图中,我正在使用一些jquery控件。我得到了jsonC# 从json格式对象获取值,c#,javascript,C#,Javascript,在我的asp.Net应用程序(MVC3)视图中,我正在使用一些jquery控件。我得到了json { "text":"Books", "state":"open", "attributes":{ "url":"/demo/book/abc", "price":100 } 如何获取属性名的值?您可以使用objectName[attributename]
{
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
如何获取属性名的值?您可以使用
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
例如。如果你
var data = {
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
}
如果属性的属性没有改变,您可以使用@furqan所说的data.attributes.url
。但是如果你的属性可以改变,你可以像这样迭代属性
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对象。谢谢,但它不起作用,elemet有属性,有带值的键url,但这不起作用。我刚刚尝试过,从我的调试器json.attributes.url“/demo/book/abc”字符串中,它看起来不错。如果您想发布更多的代码来提供一些上下文,请这样做。