/*
var data = {
keyWord: ‘123‘,
paice_code: ‘1‘,
paice_kehu: ‘1‘,
paice_more_0_number: ‘1‘,
paice_more_0_paice: ‘2‘,
paice_more_1_number: ‘3‘,
paice_more_1_paice: ‘4‘,
}
转换成 {keyword:‘123‘,paice:{code:1,kehu:1,more:{0:{number:1,paice:2},1:{number:3,paice:4}}}}
没有用数组 觉得差距不大
*/
function H_KeyStringToObj(data) { let obj = {}; for (var key in data) { arrayToObj(key.split(‘_‘), data[key], obj) }; return obj } function arrayToObj(keyName, value, allData) { let fisrtKey = keyName.splice(0, 1)[0]; allData[fisrtKey] = allData[fisrtKey] || {}; if (keyName.length == 0) { allData[fisrtKey] = value; return allData; } else { allData[fisrtKey] = arrayToObj(keyName, value, allData[fisrtKey]) } return allData; }