获取访问json数组的问题。
这是我的javascript
function getCustomerInfo(){
$.ajax({
dataType: 'json',
url:'https://host:8443/xxxxxx/xxx',
type: 'POST',
data: {requestor_email: 'honey@gmail.com'},
success:function(data){
alert(JSON.stringify(data)); //first alert
alert(data.outputMap.customerName); //second alert
alert(data.outputMap.emailId); //third alert
alert(data.outputMap.orders); //fourth alert
alert(data.outputMap.orders[0]); //fifth alert
},
error:function(data){
alert(JSON.stringify(data));
}
});
}
我的第一个警告打印出json响应,即
`
{
"targetRequestUri":"/getCustomerInfo",
"javax.servlet.request.key_size":128,
"outputMap":
{
"emailId":"honey@gmail.com",
"orders ":[
{
"orderId":"ST210340",
"orderDate":"2013-04-24 12:42:54.187",
"orderStatus":"ORDER_COMPLETED",
"totalMoney":1
}
],
"partyId ":"10810",
"customerName":"honey goyal"
},
"_FORWARDED_FROM_SERVLET_":true,
"javax.servlet.request.ssl_session":"519ee62b8656107fa3ac262c2ac8f86e0348933dc980e0078eca2fd638b55303",
"javax.servlet.request.ssl_session_id":"519ee62b8656107fa3ac262c2ac8f86e0348933dc980e0078eca2fd638b55303",
"_SERVER_ROOT_URL_":"https://host:8443",
"javax.servlet.request.cipher_suite":"TLS_ECDHE_RSA_WITH_RC4_128_SHA",
"thisRequestUri":"json"
}`
第二个警告打印正确的客户名,即honey goyal
第三个警告打印正确的emailId,即honey@gmail.com
Forth alert打印未定义,这是问题,它应该打印[object Object] s。
第五个警报也响应未定义。
提前致谢。
答案 0 :(得分:2)
根据警告的JSON字符串,订单的正确密钥名称为"orders "
(末尾有空格)。
尝试将第四个提醒更改为:alert(data.outputMap['orders ']);