javascript - 使用 JavaScript 解析 json 失败

标签 javascript json

当我调用返回 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/

相关文章:

javascript - 是否可以像在 Java 上那样从 JSTL 数组中更改获取变量值?

javascript - 空数组和排序推送的键 JavaScript

javascript - 如何在vue路由器中转到之前的状态替换当前状态

javascript - 多个带有按钮的弹出窗口

javascript - 如何使用CreateJS绘制弯曲的箭头?

javascript - 从 json 数组转换为 json 对象无法正常工作

javascript - 使用 AngularJS 或 Javascript 从现有 json 创建新的 json

php - JavaScript 中的 JSON 评估

php - 如何使用php访问Json字段

javascript - PhoneGap 的 JSON 加载问题