当我调用返回 json
格式的随机引用(标题和内容)的 api
时,我收到了 json
就好了:
ajax({ url: 'quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1', type: 'json' },
function(data) {
console.log(( JSON.stringify( data ) ));
console.log(data.content);
console.log(( JSON.stringify( data ) ));
输出:
[{
"ID":1562,
"title":"Michael Bierut",
"content":"Most of the mediocre design today comes from designers who are faithfully doing as they were taught in school: they worship at the altar of the visual.\n",
"link":"http:\/\/quotesondesign.com\/michael-bierut-3\/",
"custom_meta":{"Source":"article"}
}]
但是console.log(data.content);
输出:无。
最佳答案
尝试 console.log(data[0].content);
关于javascript - 使用 JavaScript 解析 json 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36759850/