html,js如何依次输出对象的内容

如,有如此对象:字符串来的{"name":"tom","age":22}

如何在页面输出:假设还有很多键值对

name:tom
age:22


慕仙森
浏览 1379回答 1
1回答

心有法竹

var jsonString = '{"name":"tom","age":22}';var jsonData = JSON.parse(jsonString);$scope.arr = [];for(var k in jsonData){&nbsp; &nbsp; $scope.arr.push({key:k,value:jsonData[k]});}&nbsp;<ul>&nbsp; &nbsp; <li ng-repeat="item in arr">&nbsp; &nbsp; &nbsp; &nbsp; <span>{{item.key}}</span>:<span>{{item.value}}</span>&nbsp; &nbsp; </li></ul>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript