2017-10-05 133 views
0

我需要解析缓存控制标题响应以使用缓存API响应。从响应中解析缓存控制标题值

样品响应头:

{"x-backside-transport":"OK OK","connection":"close","transfer-encoding":"chunked","access-control-allow-origin":"*","cache-control":"public, max-age=60","content-type":"application/json","date":"Thu, 05 Oct 2017 10:33:59 GMT","etag":"\"-161458570\"","x-powered-by":"Express","x-global-transaction-id":"429271565"} 

我使用console.log("------ CACHE VALUE----"+JSON.stringify(response.headers.cache-control));但这似乎每次失败。

给我的错误:ReferenceError: control is not defined

但是,当它试图用

console.log("------ CACHE VALUE----"+JSON.stringify(response.headers.connection)); 

同我能够成功地打印出日志值。我错过了什么吗?

+0

的可能的复制[无法与访问JSON属性“ - ”破折号(https://stackoverflow.com/questions/13869627/unable-to-access-json-财产与破折号) – Joe

回答

3

短跑-不适用于JSON。你可能想尝试解析像下面

response.headers["cache-control"]