Techy
Techy

Reputation: 2654

How to get a particular field value from json response

I am trying to call an external API system from my website.In the ajax response,I get the following data.

object(stdClass)#3 (3) {


["status"]=>
  string(7) "success"
  ["code"]=>
  int(200)
  ["data"]=>
  object(stdClass)#4 (3) {

    ["desktop_url"]=>
    string(113) "http://landing.beta.learning.social/remote?token=a_token_value"

    ["mobile_url"]=>
    string(115) "http://m.landing.beta.learning.social/remote?token=a_token_value"

  }
}

I need to get the value of the desktop_url field from this response.So that I can redirect page with the url from that field.I have tried with the following code.

$.ajax({
  type: "POST", 
  url: path, 
  data: "email=" + $("#email_data").val() + "&fname=" + $("#fname_data").val()+"&grade="+$("#gradeID_data").val()+
  "&lastname="+$("#lname_data").val(),
  success: function(message){
    $(message).map(function(item){console.log (item.data);});
  }
});

This is not working for me and giving me the following error

Error: Syntax error, unrecognized expression: object(stdClass)#3 (3...

Upvotes: 0

Views: 802

Answers (1)

andrew
andrew

Reputation: 9583

You need to json encode the response from the api call

<?php 
$response = $api->call($params[,...]);


header('content-type:application/json');
exit(json_encode($response));

Upvotes: 3

Related Questions