假设你有以下JSON:
{"zero":{"0":"foo","1":"foo2"},"one":"fooa","two":"foob"}
将其转换为最有效的方式是:
var zero = ['foo','foo2'];
var one = 'fooa';
var two = 'foob';
答案 0 :(得分:3)
var json = '{"zero":{"0":"foo","1":"foo2"},"one":"fooa","two":"foob"}';
var pJson = JSON.parse(json);
var zero = [ pJson.zero[0], pJson.zero[1] ];
var one = pJson.one;
var two = pJson.two;