JS遍历json方法

xiaoxiao2025-12-02  5

let json = { /** * 获得key对应的value集合 * 解析json 获得key的值 * @param key 键key * @param obj 对象 * @param result list对象存储返回结果,先要实例化对象传入[] */ parseJsonKey: function (key, obj, result) { if (obj instanceof Array) { // 遍历list for (let i in obj) { util.parseJsonKey(key, obj[i], result); } } else if (obj instanceof Object) { // 遍历object for (let i in obj) { let obj2 = obj[i]; if (i === key) { result.push(obj2); } util.parseJsonKey(key, obj2, result); } } } }; // 待续...
转载请注明原文地址: https://www.6miu.com/read-5040219.html

最新回复(0)