解析在AngularJS JSON字符串 - 给出不确定 [英] Parsing JSON String in AngularJS - Gives undefined
本文介绍了解析在AngularJS JSON字符串 - 给出不确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有一个code喜欢在我的控制下
Hi I have a code like following in my controller
myClientApp.controller('ListCtrl', function ($scope,$http,$cookieStore,$location, $routeParams) {
var data = {
"menus": {
"view": true,
"add": true,
"update": true,
"delete": true
},
"linkInfo": {
"labelColumn": "codeName",
"linkColumn": "lookupKey",
"urlInfo": "reference"
},
"resultList": [
"{\"lookupKey\":2,\"clientKey\":1,\"codeName\":\"Application.AppType\",\"codeValue\":\"ApplicationType2\",\"codeDesc\":\"##\",\"updatedBy\":null,\"internalCodeName\":\"Application.AppType\"}",
"{\"lookupKey\":3,\"clientKey\":1,\"codeName\":\"Application.Class\",\"codeValue\":\"Tier 1\",\"codeDesc\":\"Critical Application requiring immediate response in case of a disruption of Service\",\"updatedBy\":null,\"internalCodeName\":\"Application.Class\"}"
]
};
$scope.result = angular.fromJson(data.resultList);
alert($scope.result[0].codeName);
});
和它给我的未定义。为什么呢?
And It gives me undefined . Why?
推荐答案
由于 resultList
是JSON字符串,而不是一个单一的JSON字符串数组;您需要指定要脱code哪个键:
Because resultList
is an array of JSON strings, not a single JSON string; you need to specify which key you want to decode:
$scope.result = [
angular.fromJson(data.resultList[0]),
angular.fromJson(data.resultList[1])
];
alert($scope.result[0].codeName);
这篇关于解析在AngularJS JSON字符串 - 给出不确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文