For reference I'm using EasyPost (shipping API) to make PHP calls checking shipping rates and what not. Their code is all about using it to echo data back to the page as a PHP object, but I'm trying to use jQuery ajax to get JSON data back from it to use in my ember.js app.
In talking with someone from EP (EasyPost) about why I could not get it to encode to JSON correctly for my app he told me that what is returned from EP is a PHP object, and that I would need to build an array before json_encode will work.
Below is the example response from their site...
{
"id": "prcl_WDv2VzHp",
"object": "Parcel",
"length": 20.2,
"width": 10.9,
"height": 5.0,
"predefined_package": null,
"weight": 65.9,
"created_at": "2013-04-22T05:40:57Z",
"updated_at": "2013-04-22T05:40:57Z"
}
I'm not versed enough in PHP to understand how I would go about building an array from this to then be able to json_encode it.
It should also be noted that some responses have points that look like this...
"from_address": {
"id": "adr_VgoLT6Ex",
"object": "Address",
"name": "Jon Calhoun",
"company": null,
"street1": "388 Townsend St",
"street2": "Apt 20",
"city": "San Francisco",
"state": "CA",
"zip": "94107",
"country": "US",
"phone": "4154567890",
"email": null,
"created_at": "2013-04-22T05:39:57Z",
"updated_at": "2013-04-22T05:39:57Z"
},
and ...
"rates": [{
"id": "rate_nyCb6ubX",
"object": "Rate",
"service": "FirstClassPackageInternationalService",
"rate": "9.50",
"carrier": "USPS",
"shipment_id": "shp_vN9h7XLn",
"created_at": "2013-04-22T05:40:57Z",
"updated_at": "2013-04-22T05:40:57Z"
},...
Hoping someone can point me in the right direction, if I understand how to get each bit out and make it an index in the array I think I can go from there. As I really don't need some of the data that is returned anyway.