我想閱讀_body中的錯誤消息。如何在此JSON中訪問此密鑰的此值?
目前,我做的是:
的console.log(message._body.error);
但是,我越來越未定義。
當我做console.log(message._body);
我得到「{」代碼「:141,」錯誤「:」這個電話號碼已經存在!「}」
var message = {
"_body":"{"code":141,"error":"This phone number exists already!"}",
"status":400,
"ok":false,
"statusText":"Bad Request",
"type":2
};
通過以下的方式來形成這樣的後臺,我可以」 t更改其格式既不刪除雙引號
"_body":"{"code":141,"error":"This phone number exists already!"}"
如何讀取錯誤消息?
如果這是一個真正的'JSON'對象,那麼你應該'parse'。它首先('JSON.parse(obj)') –