[TYPO3-mvc] Making JSON data from object

Pascal Geldmacher pgeldmacher at best-mediaforge.com
Thu Mar 4 12:56:33 CET 2010


Am 04.03.2010 11:48, schrieb Søren Malling:
> Hi,
>
> I need to create a json string from a repository but (i guess) due to
> the use of object in the return of findAll() my json output (using
> json_encode) looks like this
>
> [{},{}]
>
> I only got 2 results in my object, so the amount of square brackets
> are correct, but there is no data.
>
> What would be the correct to solve this problem? I couldn't find any
> thing on JSON in the extbase source or from any Google searches?
>
> Cheers and thanks
>
> Søren

I think it's not possible on this way.
I need json to work with extJS so and if i want to save some data in my 
extJS components i have to write that:

$orders = $this->orderRepository->findAll();

$results = array();
foreach($orders as $order){
	$orderArray = array();
	$orderArray['id'] = $order->getUid();
	$orderArray['complete'] = $order->isComplete();
	$orderArray['payment'] = $order->getPayment();
	$orderArray['feedback'] = $order->getFeedback();
	$orderArray['pname'] = $order->getProduct()->getName();
	$orderArray['pid'] = $order->getProduct()->getUid();
	$orderArray['customer'] = $order->getCustomer()->getName();
	$orderArray['cid'] = $order->getCustomer()->getUid();
	$orderArray['sumlongprice'] = $order->getSumlongprice();
	$orderArray['quantity'] = $order->getNumber();
	$orderArray['date'] = $order->getDate()->format('d/M/Y H:i');
	$results[] = $orderArray;	
}
json_encode($results);

that works fine, ok maybe bad code, but i didn't find a better solution 
til now.

Greetings

Pascal



More information about the TYPO3-project-typo3v4mvc mailing list