我分析了一个XML文件并检索了以下JSON对象。 问题是json中有破折号,导致遍历对象的问题。不幸的是我无法摆脱它们。通过JSON对象数组迭代
$(function() {
let json = JSON.parse('{"app-app":{"$":{},"notneeded":"123","mapped":{"$":{},"match-match":[{"$":{},"name":"Foo 1","url":"/Bar 1"},{"$":{},"name":"Foo 2","url":"/Bar 2"},{"$":{},"name":"Foo 3","url":"Bar 3"}]},"Nothing":"123"}}');
var foo = Object.keys(json['app-app']['mapped']['match-match']).length;
for (var i = 0; i < foo; i++) {
console.log(json['app-app']['mapped']['match-match'][i].name);
console.log(json['app-app']['mapped']['match-match'][i].url);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
我想通过对象进行迭代,每一个 “匹配” 的孩子。类似这样的:
return [
{
name: 'Foo 1',
url: 'Bar 1'
},
[...]
]
在此先感谢您。
'value.app.mapped.match' – Weedoze