Ivanka T
Ivanka T

Reputation: 109

How print json response in php

I have the json object from remote site. When I vardump the json response. The output looks like this..

object(GSResponse)#111 (7) {
  ["errorCode":"GSResponse":private]=>
  int(0)
  ["errorMessage":"GSResponse":private]=>
  NULL
  ["rawData":"GSResponse":private]=>
  string(1808) "{
  "UID": "*********",
  }
  ]
  }

How can I access the rawData parameter in the json response using php. Is there any function to convert it into php array.

I appreciate any help.

Upvotes: 1

Views: 5504

Answers (3)

Jason
Jason

Reputation: 15358

Edited - updated to include the comments

Answer

Lets say that $gsresponsevar is an object of type gsresponse, as defined below.

decode the json response-

$myjsonresponse= json_decode($gsresponsevar->getResponseText()) ;

Alternatively retrieve the var

echo $gsresponsevar->getString('uid');

Documentation

Extract from: http://developers.gigya.com/030_Server_SDKs/PHP/Reference/Class_GSResponse

string  getString(string $key [, string $defaultValue])

Upvotes: 2

strauberry
strauberry

Reputation: 4199

this is the generic "frameworkless" native way

you can use JSON_decode to decode a JSON-string

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

$dataObject = json_decode($json);
$dataArray = json_decode($json, true);

The second parameter defines whether you get an object (accessible via $dataObject->key) or an associative array (accessible via $dataArray['key']).

Be aware of the common mistakes mentioned in the API "Example #3 common mistakes using json_decode()"

This is the Gigya-API usage way

See the answer from Jason for more details for this

$responseObject->getString('key');

Upvotes: 1

Chandresh M
Chandresh M

Reputation: 3828

you can use json_decode($json_array);

for print your resulted array you can write var_dump(json_decode($json_array));

Thankx.

Upvotes: -1

Related Questions