Reputation: 839
i have a script that returns the json results in this
Figure 1
["No=>0001","Name=>DONALD FRIMP","Address=>B BLOCK 2"]
but i want it to return like this
Figure 2
[{"No":"0001","Address":"B BLOCK 2"}]
this is my php
$data=array('No=>'.$customer->No,Address=>'.$customer->Address);
echo json_encode($data);
Any help on how to get json to return like figure 2
.
Upvotes: 0
Views: 393
Reputation: 805
try this
$data=array('No'=>$customer->No,'Address'=>$customer->Address);
echo json_encode(array($data));
Upvotes: 1
Reputation: 11328
Use a proper array:
$data=array('No' => $customer->No, 'Address' => $customer->Address);
echo json_encode($data);
That will output a JSON object. If you want it wrapped in a list in JSON, wrap it in an array in PHP:
echo json_encode(array($data));
Upvotes: 1
Reputation: 133390
you could use an array
$myArray[]['No'] = "0001";
$myArray[]['Address'] = "B BLOCK 2";
echo json_encode($myArray);
Upvotes: 0