访问 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"
}`
第二个警报打印正确的客户名称,即蜂蜜 goyal
第三个警报打印正确的 emailId 即 honey@gmail.com
Forth alert 打印 undefined,这就是问题所在,它应该打印 [object Object]s。
第五警报也响应未定义。
提前致谢。