项目中发现的一些关于JavaScript中JSON的注意点

时间:2022-07-23 18:20:14

一个是怎样创建JSON:

var obj = {};
obj['name'] = value;
obj['anotherName'] = anotherValue;

假设要创建多级的JSON,则:

ips[ipId] = {};
ips[ipId]['name'] = value;
ips[ipId]['anotherName'] = anotherValue;

注意要用bracket[]而不能用点. 来訪问json object

bracket尽管写起来麻烦一些,可是能够避免非常多错误!

http://*.com/questions/4071499/dynamically-add-variable-name-value-pairs-to-json-object

http://www.dev-archive.net/articles/js-dot-notation/

http://*.com/questions/7102704/how-to-use-variables-in-dot-notation-like-square-bracket-notation