我有这样的对象我需要得到“GetToolInfo”这个名字:
{"GetToolInfo":{
"Item":[
{
"_Key":"DefaultPath",
"_Value":"C:\\Users\\vkedarix\\Desktop\\TAT\\Host\\DefaultWorkSpace.xml"
},{
"_Key":"IsLicenseAgreed",
"_Value":"1"
}
]
}
}
答案 0 :(得分:0)
嗨,此示例向您展示如何从对象获取密钥:
var app = angular.module("app", []);
app.controller("ctrl", function ($scope, $filter) {
var foo = {
"GetToolInfo": {
"Item": [
{
"_Key": "DefaultPath",
"_Value": "C:\\Users\\vkedarix\\Desktop\\TAT\\Host\\DefaultWorkSpace.xml"
}, {
"_Key": "IsLicenseAgreed",
"_Value": "1"
}
]
}
};
for (var key in foo) {
console.log(key);
$scope.key = key
}
});
<!doctype html>
<html ng-app="app" ng-controller="ctrl">
<head>
</head>
<body>
{{key}}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</body>
</html>