I am getting below sample json data as input,
var JSONDATA =
{
"MainNode": {
"_attributes": {
"class": "ABC",
"projectclass": "MyProject",
"prjname": "PrjName",
"enabled":"true"
},
"PrjProp": {
"_attributes": {
"name": "MyProject.save"
},
"_text": true
}
}
}
Using Jquery or Javascript, I want to get the "projectclass" value in first "_attributes". There could be multiple "_attributes" in JSON object but the requirement to the "projectclass" (fixed) from the first (fixed) "_attributes" only.
This can be achieved like, console.log(JSONDATA.MainNode._attributes.testclass);
but "MainNode" is not fixed, this can be "OtherNode". So how to handle this is variable ? I tried , console.log(Object.keys($scope.testplan)[0]); which shows main node name but how to use this in console.log(JSONDATA.MainNode._attributes.testclass); as variable ?
Please suggest. Thanks