I have this json data, stored in a jquery variable "jsondata
":
var jsondata = {
"Name": {
"Jaken": {},
"Test": {},
"Hello": {}
},
"Date": {
"Today": {},
"Tomorrow": {},
"Wednesday": {}
},
"Description": {
"Me": {},
"Tester": {},
"World": {}
},
"Another": {
"Test": {},
"Test2": {}
}
};
I'm trying to find out how to get the word "Test" as a string.
I've tried alert(jsondata.Another[1]);
, but that is, understandably, undefined
. I've tried alert(value.jsondata.Another[1]);
(Not sure why I thought this would work, but it was worth a shot I guess.
Is there any documentation that shows how to find the key name of json data in jquery as a string?
I have this json data, stored in a jquery variable "jsondata
":
var jsondata = {
"Name": {
"Jaken": {},
"Test": {},
"Hello": {}
},
"Date": {
"Today": {},
"Tomorrow": {},
"Wednesday": {}
},
"Description": {
"Me": {},
"Tester": {},
"World": {}
},
"Another": {
"Test": {},
"Test2": {}
}
};
I'm trying to find out how to get the word "Test" as a string.
I've tried alert(jsondata.Another[1]);
, but that is, understandably, undefined
. I've tried alert(value.jsondata.Another[1]);
(Not sure why I thought this would work, but it was worth a shot I guess.
Is there any documentation that shows how to find the key name of json data in jquery as a string?
Share asked Aug 25, 2015 at 21:19 JakenJaken 1,3434 gold badges24 silver badges47 bronze badges3 Answers
Reset to default 6No need to use jQuery
. Use Object.keys
var jsondata = {
"Name": {
"Jaken": {},
"Test": {},
"Hello": {}
},
"Date": {
"Today": {},
"Tomorrow": {},
"Wednesday": {}
},
"Description": {
"Me": {},
"Tester": {},
"World": {}
},
"Another": {
"Test": {},
"Test2": {}
}
};
console.log(Object.keys(jsondata.Another)[0]);
You can use Object.keys to get the keys of the object as an array:
Object.keys(jsondata.Another)[0];
This actually isn't JSON, it's an object. The variable you are looking for needs to be accessed by the key, not 1
:
alert(jsondata.Another.Test2);
As a side note...if you wanted to manipulate JSON, you would use JSON.parse()
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744862156a4597768.html
评论列表(0条)