I have a controller that returns a JSON on the page. This is the code

//Above in the code
injection of \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory

    "orderId"      => $orderId,
    "status"       => $order->getStatus(),
    "grandTotal"   => number_format($order->getGrandTotal(),2),
    "totalFacture" => ...,
    "items"        => $arrItems,

return $this->resultJsonFactory->create()->setData($result);

Then I . have a Plugin that intercepts the URL and I should retrieve this JSON and process it.

For now this is what I have:

public function afterExecute(\MyComp\MyMod\Controller\Test\GetOrderInfo $GetOrderInfo, $result)

       //return $result; //Displays the JSON in the browser properly

       //Pass trough the JSON obj OR Retrieve the real JSON string
       //Not working !!  
       foreach ($result as $obj){
           echo $obj->orderId;

       //Another attempt shows that $result is not a JSON object it self 
       $class_methods = get_class_methods($result);
       foreach ($class_methods as $method_name)
          echo "$method_name<br/>";


I can't use json_decode because $result is not a string, enev if I see in the browser the expected JSON.

So, how could I retrieve that JSON string and convert it into array?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.