var JSONText = '{"c":{"a":[{"name":"cable - black","value":2},{"name":"case","value":2}]},"o":{"v":[{"name":"over the ear headphones - white/purple","value":1}]},"l":{"e":[{"name":"lens cleaner","value":1}]},"h":{"d":[{"name":"hdmi cable","value":1},{"name":"hdtv essentials (hdtv cable setup)","value":1},{"name":"hd dvd \u0026 blue-ray disc lens cleaner","value":1}]}'
var JSONObject = JSON.parse(JSONText);
var c = JSONObject["c"];
var o = JSONObject["o"];
var obj = [];
for(n1 in yourjson)
for(n1_1 in yourjson[n])
for(n1_2 in yourjson[n][n1_1])
obj[n1_2[name]] = n1_2[value];
批准代码
for(n1 in yourobj){
for(n1_1 in yourobj[n1]){
for(n1_2 in yourobj[n1][n1_1]){
for(n1_3 in yourobj[n1][n1_1][n1_2]){
obj[yourobj[n1][n1_1][n1_2].name]=yourobj[n1][n1_1][n1_2].value;
}
}
}
}
console.log(obj);
var data = JSON.parse('{"c":{"a":{"name":"cable - black","value":2}}}')
for (var event in data) {
var dataCopy = data[event];
for (data in dataCopy) {
var mainData = dataCopy[data];
for (key in mainData) {
if (key.match(/name|value/)) {
alert('key : ' + key + ':: value : ' + mainData[key])
}
}
}
}