完整代码:
$.post('test.php', {
id: id
},function (data) {
console.log(data);
var Server = data.response.server;
var Photo = data.response.photo;
console.log(Server);
console.log(Photo);
});
在data
我得到json:
{
"server":9458,
"photo":
"[{\"photo\":\"0d6a293fad:x\",\"sizes\":
[[\"s\",\"9458927\",\"1cb7\",\"PX_xDNKIyYY\",75,64],
[\"m\",\"9458927\",\"1cb8\",\"GvDZr0Mg5zs\",130,111],
[\"x\",\"9458927\",\"1cb9\",\"sRb1abTcecY\",420,360],
[\"o\",\"9458927\",\"1cba\",\"J0WLr9heJ64\",130,111],
[\"p\",\"9458927\",\"1cbb\",\"yb3kCdI-Mlw\",200,171],
[\"q\",\"9458927\",\"1cbc\",\"XiS0fMy-QqI\",320,274],
[\"r\",\"9458927\",\"1cbd\",\"pU4VFIPRU0k\",420,360]],
\"kid\":\"7bf1820e725a4a9baea4db56472d76b4\"}]",
"hash":"f030356e0d096078dfe11b706289b80a"
}
我想获取参数server
和photo[photo]
为此我使用:
var Server = data.server;
var Photo = data.photo;
console.log(Server);
console.log(Photo);
但在concole我得到undefined
比我使用代码:
var Server = data.response.server;
var Photo = data.response.photo;
console.log(Server);
console.log(Photo);
但现在在控制台中我看到:
Uncaught TypeError: Cannot read property 'server' of undefined
为什么我会出错以及如何获取参数?
PS:所有代码 php 和 jquery 在这里找到