我已将JSON字符串打印到控制台,但无法访问JSON.parse之后的值

时间:2019-06-27 16:53:12

标签: javascript json ajax

我已经编写了一个PHP脚本,用于创建消息签名并将响应返回给PHP服务器,其中包含一些JSON数据和HTTP标头值。我可以将其打印到浏览器控制台,但似乎无法访问任何响应参数。

我正在尝试从响应中访问“客户端令牌”和publicKeyBase64。

我尝试将JSON字符串的一部分分配给一个变量,但是我似乎只能得到完整的响应,而不是特定的响应。

这是PHP脚本运行后向控制台的输出。

HTTP/1.1 200 Connection established



HTTP/1.1 200 OK

Date: Thu, 27 Jun 2019 16:46:31 GMT

Content-Type: application/json; charset=utf-8

Transfer-Encoding: chunked

Connection: keep-alive

X-Backside-Transport: OK OK

Access-Control-Allow-Methods: POST, OPTIONS

Access-Control-Allow-Origin: *

Client-Token: AtH9LDRAhJb9clBMCVLxzlCABP9P

Etag: W/"26e-7Vyri3o4GCbZ3L062iQdKB0WbEM"

X-Vcap-Request-Id: 0ce9d709-384b-4d72-4b2f-924114ad1494

X-Global-Transaction-ID: d5e47cc55d14f2e7d6c13def

Nonce: 2660210173

X-Trace-Id: e22a5295587c4b6ba19c211b4c0b4d26

Strict-Transport-Security: max-age=31536000; includeSubDomains

X-Content-Type-Options: nosniff



{"publicKeyBase64":"LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFzYVBtNHVKU0E2QktqdTQzVUlRaQptMTVWNWMyTU02MFIrQ01IQ3VOa2tkOXpLZHRySEJidnBSa0NReW1iZFhHR0ltU3FQemN6OEk1L1RKdXB3ODJPCmhtKzQ1bHVJREUrdFJIaWI5cFBiWGRWNkFTR1Z3N1ZpRnJiYU5lZU1PNi9FRmZiL0FiUmtOKzhWMGhIcnVZWEQKbitkQWEwY3Nwbnc1NFRtaWp0THhpRmFJdXdRUGNoUGZxZlEyUDE1VVJaV3dOdU55WWduL0lTSFNCKytMWmRrZwpDcklYcFlyVVhrcVJyNXBPdHRMeTVGdFd0bjBPZEluaitBczBoSlZjai9aZTY3YS9GOEJORDZEL1VwOU1CUisxCld2OWR1aFBCSnREUG5jTkRicCs1Tmx1WVdBTllweUNjUmFNUDJud0NnNnNEcW1kN0puV21IT3cycDFIWkhENXoKYXdJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0t"}

var json = <?php echo json_encode($json_response); ?>;
var response = JSON.stringify(json);    

console.log(JSON.parse(response));

console.log(response.publicKeyBase64);

使用上述Javascript,我无法为publicKeyBase64定义

0 个答案:

没有答案