【发布时间】:2018-02-10 16:07:57
【问题描述】:
我有一个 JSON 对象 event.body,其中包含 {"article_url": "http://technewstt.com/bd1108/"} 我如何访问 article_url 的值,换句话说,我想使用字符串 http://technewstt.com/bd1108/。
我试过event.body.article_url 和event.article_url,它们都是undefined
【问题讨论】:
-
您确定
event.body确实包含该值吗?因为event.body.article_url应该可以工作。 -
@GrégoryNEUT 是的,我很确定,因为我在
event.body上做了一个console.log,它显示其中的内容{"article_url": "http://technewstt.com/bd1108/"} -
console.log(typeof event.body)和console.log(Object.keys(event.body))怎么样 -
所以试试
JSON.parse(event.body).article_url -
@GrégoryNEUT
JSON.parse(event.body).article_url工作谢谢
标签: javascript json node.js object