Javascript无法访问对象键值......它们周围有引号

gba*_*hik 1 javascript string variables key object

所以我需要访问此对象中的键值"key":

{
  "__v": 0,
  "_id": "5317b71c902ff0080046349f",
  "user": "530ef48599c41200009bad9f",
  "email": "asdfa@sdgdf.com",
  "btcId": "9HjBb9eUhyXMKuVxSrTSkg",
  "name": "Bitcoin Payments",
  "dlFile": "a43ca076-4802-4cca-9648-82b2569ffc60.docx",
  "key": "3518d5ce-badf-495c-a08f-dc28bb6d8a64",
  "created": "2014-03-05T23:45:32.480Z"
}
Run Code Online (Sandbox Code Playgroud)

但是这段代码不起作用:

console.log(body.key) -> Undefined
console.log(body['key'] -> undefined
console.log(body['"key"'] -> undefined
Run Code Online (Sandbox Code Playgroud)

body是存储对象的位置.

我认为它与键的字符串有关?或者在他们周围有""?但是我没有创建body变量,所以我无法控制它...

有关如何使其工作的任何想法?

Cil*_*lan 6

However I'm not creating the body variable so I can't control this...

这听起来像一个GET请求,所以如果是JSON数据,请用JSON.parse以下方法解析:

console.log(JSON.parse(body).key)
Run Code Online (Sandbox Code Playgroud)