json编码多维数组获取值
json encode multidimensional array get value
Array
(
[0] => Array
(
[sysid] => 1
[code] => 140101000
[name] => China
[parentid] => 1
)
[1] => Array
(
[sysid] => 2
[code] => 140102000
[name] => Japan
[parentid] => 1
)
[2] => Array
(
[sysid] => 3
[code] => 140103000
[name] => Hongkong
[parentid] => 1
)
)
这是我从 print_r 请求中获得的数组 它来自 php 这是我使用的多维数组 json_encode
现在这是我从成功中获得的数据.我想从此 json 中获取 sysid 和名称的所有值,并将其放入 select 选项中,这怎么可能
我在下面使用了这段代码,但我得到了未定义的结果,我得到了 4,000 个结果
PAIR 0: undefined
PAIR 0: undefined
PAIR 1: undefined
PAIR 1: undefined
for (var i = 0; i < data.length; i++) {
console.log("PAIR " + i + ": " + data[i].sysid);
console.log("PAIR " + i + ": " + data[i].name);
}
UPDATE
我不好第一个是print_r这是json
[{"sysid":"1","code":"140101000","name":"China","parentid":"1"},{"sysid":"2","code":"140102000","name":"Japan","parentid":"1"},
{"sysid":"3","code":"140103000","name":"Hongkong","parentid":"1"}]
ajax 是
$.ajax({
type: 'POST',
url: '../include/country.php',
data: {
id: id
},
success: function(data) {
// the next thing you want to do
var obj = data;
console.log(obj);
//for (var i = 0; i < data.length; i++) {
//console.log("PAIR " + i + ": " + data[i].sysid);
//console.log("PAIR " + i + ": " + data[i].name);
//}
}
});
$.ajax({
type: 'GET',
url: '../include/country.php',
dataType : "json",
data: {
id: id
},
success: function(data) {
for(var i = 0; i < data.length; i++) {
console.log("PAIR " + i + ": " + data[i].sysid);
console.log("PAIR " + i + ": " + data[i].name);
}
}
});
Array
(
[0] => Array
(
[sysid] => 1
[code] => 140101000
[name] => China
[parentid] => 1
)
[1] => Array
(
[sysid] => 2
[code] => 140102000
[name] => Japan
[parentid] => 1
)
[2] => Array
(
[sysid] => 3
[code] => 140103000
[name] => Hongkong
[parentid] => 1
)
)
这是我从 print_r 请求中获得的数组 它来自 php 这是我使用的多维数组 json_encode
现在这是我从成功中获得的数据.我想从此 json 中获取 sysid 和名称的所有值,并将其放入 select 选项中,这怎么可能
我在下面使用了这段代码,但我得到了未定义的结果,我得到了 4,000 个结果
PAIR 0: undefined
PAIR 0: undefined
PAIR 1: undefined
PAIR 1: undefined
for (var i = 0; i < data.length; i++) {
console.log("PAIR " + i + ": " + data[i].sysid);
console.log("PAIR " + i + ": " + data[i].name);
}
UPDATE
我不好第一个是print_r这是json
[{"sysid":"1","code":"140101000","name":"China","parentid":"1"},{"sysid":"2","code":"140102000","name":"Japan","parentid":"1"},
{"sysid":"3","code":"140103000","name":"Hongkong","parentid":"1"}]
ajax 是
$.ajax({
type: 'POST',
url: '../include/country.php',
data: {
id: id
},
success: function(data) {
// the next thing you want to do
var obj = data;
console.log(obj);
//for (var i = 0; i < data.length; i++) {
//console.log("PAIR " + i + ": " + data[i].sysid);
//console.log("PAIR " + i + ": " + data[i].name);
//}
}
});
$.ajax({
type: 'GET',
url: '../include/country.php',
dataType : "json",
data: {
id: id
},
success: function(data) {
for(var i = 0; i < data.length; i++) {
console.log("PAIR " + i + ": " + data[i].sysid);
console.log("PAIR " + i + ": " + data[i].name);
}
}
});