下面是我的代码。请帮我循环一下。我想循环完整的 JSON 并进行一些验证,但我无法循环遍历它。我是第一次做,如果any1可以帮助我,那就太好了。
有什么方法可以过滤 JSON 对象。例如,我想搜索 audit1 asgn值。过滤器可以是动态的,就像它可以是 audit1 或 audit11。我也想知道如何将上面的 json 转换为数组。这将使我的搜索变得容易(以防无法通过直接 JSON 搜索进行搜索)。
function fnMultiRowValidation(){
var vStatus = 5,
vJson = '{"tpaCo":[{"name":"Audit Company1",\
"aud":[{"name":"auditor1","asgn":"1","fnds":"1","lead":"1"},\
{"name":"auditor2","asgn":"1","fnds":"0","lead":"1"},\
{"name":"auditor3","asgn":"0","fnds":"1","lead":"0"},\
{"name":"auditor4","asgn":"1","fnds":"1","lead":"0"},\
{"name":"auditor5","asgn":"1","fnds":"1","lead":"0"},\
{"name":"auditor6","asgn":"0","fnds":"1","lead":"0"},\
{"name":"auditor7","asgn":"1","fnds":"1","lead":"0"},\
{"name":"auditor8","asgn":"1","fnds":"1","lead":"0"},\
{"name":"auditor9","asgn":"0","fnds":"1","lead":"0"},\
{"name":"auditor10","asgn":"1","fnds":"1","lead":"0"},\
{"name":"auditor11","asgn":"1","fnds":"1","lead":"0"}]},\
{"name":"Audit Company2",\
"aud":[{"name":"auditor3","asgn":"1","fnds":"1","lead":"1"},\
{"name":"auditor4","asgn":"1","fnds":"1","lead":"0"}\
]\
}\
]}';
var vObj = JSON.parse(vJson);
for (var i=0;i<vObj.tpaCo.length;i++){
$.each(vObj.tpaCo[i], function(key, value) {
console.log(key +':'+ value);
if(typeof(value)=='object'){
//console.log('Auditor length:'+vObj.tpaCo.value.length);
}
});
}
}