I have the following JSON below that I want to parse and get the value of the TotalRows
. However, in my PHP and JavaScript it returns an error or undefined when I try to access it and I am not sure why.
My code for PHP is, where $customers
returns the JSON below:
$customers = $customerDB->findCustomer(5, 1); $arr = json_decode($customers, true); echo $arr["TotalRows"];
For JavaScript:
var data = <?php echo json_encode($customers); ?>; console.log(data.TotalRows)
[ { "TotalRows":91, "Rows":[ { "CompanyName":"Ana Trujillo Emparedados y helados", "ContactName":"Ana Trujillo", "ContactTitle":"Owner", "City":"M\u00e9xico D.F.", "Country":"Mexico" }, { "CompanyName":"Antonio Moreno Taquer\u00eda", "ContactName":"Antonio Moreno", "ContactTitle":"Owner", "City":"M\u00e9xico D.F.", "Country":"Mexico" }, { "CompanyName":"Around the Horn", "ContactName":"Thomas Hardy", "ContactTitle":"Sales Representative", "City":"London", "Country":"UK" }, { "CompanyName":"Berglunds snabbk\u00f6p", "ContactName":"Christina Berglund", "ContactTitle":"Order Administrator", "City":"Lule\u00e5", "Country":"Sweden" }, { "CompanyName":"Blauer See Delikatessen", "ContactName":"Hanna Moos", "ContactTitle":"Sales Representative", "City":"Mannheim", "Country":"Germany" } ] } ]
https://stackoverflow.com/questions/66073415/unable-to-retrieve-json-value-from-php-and-javascript February 06, 2021 at 11:54AM
没有评论:
发表评论