0

Getting problem to access json array.

this my javascript

function getCustomerInfo(){
    $.ajax({
    dataType: 'json',
    url:'https://host:8443/xxxxxx/xxx',
    type: 'POST',
        data: {requestor_email: '[email protected]'},
    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));
        }
   });
}

My first alert prints the json response i.e

`

{
 "targetRequestUri":"/getCustomerInfo",
 "javax.servlet.request.key_size":128,
 "outputMap":
            {
             "emailId":"[email protected]",
             "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"
}`

Second alert prints the correct customerName i.e honey goyal

Third alert prints the correct emailId i.e [email protected]

Forth alert prints the undefined, this is the problem, it should prints [object Object]s.

Fifth alert also responds the undefined.

Thanks in advance.

1 Answer 1

2

The correct key name for orders is "orders " (with a space at the end) as per the alerted JSON string.

Try changing the fourth alert to: alert(data.outputMap['orders ']);

1
  • thanks man, yeah good eye ;)..i was trying to work it from 3 hours. Commented May 24, 2013 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.