var data = JSON.parse('{"orders":[{"orderId":654654654,"orderNumber":"5555555","orderKey":"000000000000-0000000000000","orderDate":"2018-01-18T07:17:58.0000000","createDate":"2018-01-18T07:26:29.1600000","modifyDate":"2018-01-18T07:26:30.0100000","paymentDate":"2018-01-18T07:17:59.0000000","shipByDate":null,"orderStatus":"awaiting_shipment","customerId":55555555,"customerUsername":"username","customerEmail":"email@here.com","billTo":{"name":"JOHN DOE","company":null,"street1":null,"street2":null,"street3":null,"city":null,"state":null,"postalCode":null,"country":null,"phone":null,"residential":null,"addressVerified":null},"shipTo":{"name":"JOHN DOE","company":null,"street1":"123 AVE","street2":"LOGISTICS","street3":null,"city":"MIAMI","state":"FL","postalCode":"33166","country":"US","phone":"333-333-3333","residential":false,"addressVerified":"Address validated successfully"},"items":[{"orderItemId":654654654654,"lineItemKey":"654654654654654","sku":"","name":"IBM Series X3850 X5 4x E7-8870 2.4ghz 40-Cores / 128gb / 8x 146gb / M5015","imageUrl":"https://i.ebayimg.com/5654654654F","weight":{"value":1280.00,"units":"ounces","WeightUnits":1},"quantity":1,"unitPrice":1139.99,"taxAmount":0.00,"shippingAmount":null,"warehouseLocation":null,"options":[],"productId":null,"fulfillmentSku":null,"adjustment":false,"upc":null,"createDate":"2018-01-18T07:26:29.16","modifyDate":"2018-01-18T07:26:29.16"}],"orderTotal":1228.28,"amountPaid":1228.28,"taxAmount":0.00,"shippingAmount":88.29,"customerNotes":null,"internalNotes":null,"gift":false,"giftMessage":null,"paymentMethod":"PayPal","requestedShippingService":"FedExHomeDelivery","carrierCode":"fedex","serviceCode":"fedex_home_delivery","packageCode":"package","confirmation":"none","shipDate":null,"holdUntilDate":null,"weight":{"value":1280.00,"units":"ounces","WeightUnits":1},"dimensions":{"units":"inches","length":35.00,"width":23.00,"height":15.00},"insuranceOptions":{"provider":null,"insureShipment":false,"insuredValue":0.0},"internationalOptions":{"contents":null,"customsItems":null,"nonDelivery":null},"advancedOptions":{"warehouseId":65465465,"nonMachinable":false,"saturdayDelivery":false,"containsAlcohol":false,"mergedOrSplit":false,"mergedIds":[],"parentId":null,"storeId":4654654654,"customField1":null,"customField2":null,"customField3":null,"source":null,"billToParty":null,"billToAccount":null,"billToPostalCode":null,"billToCountryCode":null,"billToMyOtherAccount":null},"tagIds":[654654],"userId":null,"externallyFulfilled":false,"externallyFulfilledBy":null,"labelMessages":null}],"total":1,"page":1,"pages":1}');
var orderId = data.orders[0].orderId;
console.log(orderId);
This is the object:
{"orders":[{"orderId":654654654,"orderNumber":"5555555","orderKey":"000000000000-0000000000000","orderDate":"2018-01-18T07:17:58.0000000","createDate":"2018-01-18T07:26:29.1600000","modifyDate":"2018-01-18T07:26:30.0100000","paymentDate":"2018-01-18T07:17:59.0000000","shipByDate":null,"orderStatus":"awaiting_shipment","customerId":55555555,"customerUsername":"username","customerEmail":"email@here.com","billTo":{"name":"JOHN DOE","company":null,"street1":null,"street2":null,"street3":null,"city":null,"state":null,"postalCode":null,"country":null,"phone":null,"residential":null,"addressVerified":null},"shipTo":{"name":"JOHN DOE","company":null,"street1":"123 AVE","street2":"LOGISTICS","street3":null,"city":"MIAMI","state":"FL","postalCode":"33166","country":"US","phone":"333-333-3333","residential":false,"addressVerified":"Address validated successfully"},"items":[{"orderItemId":654654654654,"lineItemKey":"654654654654654","sku":"","name":"IBM Series X3850 X5 4x E7-8870 2.4ghz 40-Cores / 128gb / 8x 146gb / M5015","imageUrl":"https://i.ebayimg.com/5654654654F","weight":{"value":1280.00,"units":"ounces","WeightUnits":1},"quantity":1,"unitPrice":1139.99,"taxAmount":0.00,"shippingAmount":null,"warehouseLocation":null,"options":[],"productId":null,"fulfillmentSku":null,"adjustment":false,"upc":null,"createDate":"2018-01-18T07:26:29.16","modifyDate":"2018-01-18T07:26:29.16"}],"orderTotal":1228.28,"amountPaid":1228.28,"taxAmount":0.00,"shippingAmount":88.29,"customerNotes":null,"internalNotes":null,"gift":false,"giftMessage":null,"paymentMethod":"PayPal","requestedShippingService":"FedExHomeDelivery","carrierCode":"fedex","serviceCode":"fedex_home_delivery","packageCode":"package","confirmation":"none","shipDate":null,"holdUntilDate":null,"weight":{"value":1280.00,"units":"ounces","WeightUnits":1},"dimensions":{"units":"inches","length":35.00,"width":23.00,"height":15.00},"insuranceOptions":{"provider":null,"insureShipment":false,"insuredValue":0.0},"internationalOptions":{"contents":null,"customsItems":null,"nonDelivery":null},"advancedOptions":{"warehouseId":65465465,"nonMachinable":false,"saturdayDelivery":false,"containsAlcohol":false,"mergedOrSplit":false,"mergedIds":[],"parentId":null,"storeId":4654654654,"customField1":null,"customField2":null,"customField3":null,"source":null,"billToParty":null,"billToAccount":null,"billToPostalCode":null,"billToCountryCode":null,"billToMyOtherAccount":null},"tagIds":[654654],"userId":null,"externallyFulfilled":false,"externallyFulfilledBy":null,"labelMessages":null}],"total":1,"page":1,"pages":1}
To get the orderId value in my returned json object I use: (data.order) is the object.
data.order[0].orders.orderId
I just get not returned value or undefined on anything I try. If I output the data.order object I obviously get the whole JSON object. I've read through several threads here and can seem to find a object/array as complex as the one I'm working on. Any help is appreciated.
I removed the return array to dumb it down. Here is my function in case you were curious. Any if you don't understand some odd markup I'm using the Symfony framework and Twig.
function getOrderInfo( orderId, location ){
var data = {
id : orderId
};
$.ajax({
type: "POST",
url: "{{ path('Dashboard_OrderTracker_orderInfo') }}",
data: data
})
.done(function (data) {
var jsondata = JSON.parse(data);
var orderNumber = jsondata.orders[0].orderNumber;
var name = jsondata.orders[0].shipTo.name;
var phone = jsondata.orders[0].shipTo.phone;
var customerEmail = jsondata.orders[0].customerEmail;
$('#info').html(
"<b>Order number:</b> " + orderNumber + "<br/>" +
"<b>Customer Name:</b> " + name + "<br/>" +
"<b>Cutomer Phone:</b> " + phone + "<br/>" +
"<b>Customer Email:</b> <a href='mailto:" + customerEmail + ">" + customerEmail + "</a><br/>"
);
$( "#info" ).dialog("option", "position", {
of: location
}).dialog("open");
})
.fail(function ( xhr.responseText ) {
alert(xhr);
});
};