I have a link with a magento shop, which outputs the following json(please ignore the bogus values for testing purposes):
jsfiddle http://jsfiddle.net/ZkZ4D/
non pretty formatting, output by php
[[{"customer_address_id":"4","created_at":"2013-01-14 10:49:59","updated_at":"2013-01-14 10:49:59","city":"abc town","country_id":"NL","firstname":"john","lastname":"doe","postcode":"7091 eh","street":"mwhahah 47
mwhgahahahaha","telephone":"31645494440","is_default_billing":true,"is_default_shipping":true}],[{"customer_address_id":"4","created_at":"2013-01-14 10:49:59","updated_at":"2013-01-14 10:49:59","city":"abc town","country_id":"NL","firstname":"john","lastname":"doe","postcode":"7091 eh","street":"mwhahah 47
mwhgahahahaha","telephone":"31645494440","is_default_billing":true,"is_default_shipping":true}]]
pretty formatting for human reading
[
[
{
"customer_address_id": "4",
"created_at": "2013-01-14 10:49:59",
"updated_at": "2013-01-14 10:49:59",
"city": "abc town",
"country_id": "NL",
"firstname": "john",
"lastname": "doe",
"postcode": "7091 eh",
"street": "mwhahah 47
mwhgahahahaha",
"telephone": "31645494440",
"is_default_billing": true,
"is_default_shipping": true
}
],
[
{
"customer_address_id": "4",
"created_at": "2013-01-14 10:49:59",
"updated_at": "2013-01-14 10:49:59",
"city": "abc town",
"country_id": "NL",
"firstname": "john",
"lastname": "doe",
"postcode": "7091 eh",
"street": "mwhahah 47
mwhgahahahaha",
"telephone": "31645494440",
"is_default_billing": true,
"is_default_shipping": true
}
]
]
How do I get the above json?
php code
class ajax extends plantinaNLmagento
{
public function __construct()
{
parent::__construct();
}
public function getCustomerAdressAjax()
{
$id = (int)$_GET['customerid'];
$q = $this->db->query("SELECT * FROM `tbl_magento_users` WHERE `core_id`=:ID",array('ID'=>$id));
$customeradresses = array();
while($who = $q->fetchObject())
{
$x=$this->mage->call('customer_address.list',$who->magento_ID);
array_push($customeradresses,$x);
array_push($customeradresses,$x);
}
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($customeradresses);
}
}
I'm pushing the $customeraddress
twice for testing purposes.
Now if I paste the resulting json into jsonlint or other json validators it all says it's valid json.
When I use it int he function JSON.parse or jQuery.parseJSON I get a unexected token error, but it doesn't say which token or where, and since my json passes the valdation I'm totally at a loss which token it fails at.
I must be missing something in the category of facepalm but I simply can't find it...
error message
SyntaxError: Unexpected token