0
可能重复:
How do I reference a javascript object property with a hyphen in it?JavaScript对象 - 不能包含访问键 ' - '
我有以下格式的JSON:
var response1="{" +
"\"code\":\"200\"," +
"\"requestID\":\"1002\"," +
"\"body\":\"[{" +
"\\\"author\\\":\\\"sumit\\\"," +
"\\\"id\\\":\\\"ABX-002\\\"," +
"\\\"title\\\":\\\"How to make Android APK in 2 seconds :)\\\"" +
"}," +
"" +
"{" +
"\\\"author\\\":\\\"sumit\\\"," +
"\\\"id\\\":\\\"ABX-002\\\"," +
"\\\"title\\\":\\\"How to make Android APK in 2 seconds :)\\\"" +
"}," +
"{"+
"\\\"author\\\":\\\"sumit\\\"," +
"\\\"id\\\":\\\"ABX-002\\\"," +
"\\\"title\\\":\\\"How to make Android APK in 2 seconds :)\\\"" +
"}" +
"]\"," +
"\"headers\":{\"Server\":\"Apache-Coyote/1.1\"," +
"\"Content-Type\":\"text/xml\"," +
"\"Content-Length\":\"131\"," +
"\"Date\":\"Thu, 06 Sep 2012 09:10:26 GMT\"" +
"}" +
"}";
我想要解析内容类型密钥。 所以我写了下面的代码来解析值:
var jsonResponse = jQuery.parseJSON(response1);
var contentType = jsonResponse.headers.Content-Type;
我不能够得到的Content-Type和Content-Length的值。 任何帮助,将不胜感激。 非常感谢
你为什么双重逃脱身体JSON? – Bergi
嗨Bergi ...我已经作为字符串对象的响应,所以我已经添加适当的转义字符,使其成为一个适当的JSON字符串。 –