how to get json object and its values

Hi, I want to get all the values that is coming from an apiurl. how can i do so here using yii2.

public function actionSuggestions()

{   


    $listingId = Yii::$app->request->get('listing_id');


    $apiUrl = "example.com/asdga/hfdsu"


    $suggestions = file_get_contents($apiUrl);


    $suggestions = json_decode($suggestions, TRUE);





    return $this->render('suggestions' , array(





        'company_name' => $suggestions,





        'listingId' => $listingId,


        'suggestions' => $suggestions,


    ));


}

//In json format.

{

"tbl_supplierOrderDetails": [

{


  "num": 1,


  "user_id": 3496,


  "priority": "A.closed",


  "no_of_times": 5,


  "username": "eyuw",


  "company_name": "djff",


  "email": "abc@gmail.com",


  "contact_no": "9999999999",


  "origin": "abc",


  "dest": "xyz",


  "vehicle_class": "abc,


  "vehicle_type": "abc",


  "notes": "TCS_"


}]

"tbl_userContactDetails": [

{


  "user_id": 500,


  "contact_name": "Mr abc",


  "contact_email": "abc@gmail.com",


  "contact_mobile": 9999999999,


  "contact_mobile2": null


}]

}

Here is a good article explaining several ways to get data out of json structures.

This is just plain PHP, there are no YII specific issues.

http://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php

On an unrelated noteā€¦

On the toolbar for the post editor on this forum, there is a button for "Insert Code Snippet". It will insert some tags that allow you to put formatted code such as what you had in your post. It makes things look nicer and easier to read.

Welcome to YII!!

-John