开发者

How print json response in php

开发者 https://www.devze.com 2023-03-08 01:51 出处:网络
I have the json object from remote site. When I vardump the json response. The output looks like this..

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)
  [开发者_StackOverflow社区"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.


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])


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');


you can use json_decode($json_array);

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

Thankx.

0

精彩评论

暂无评论...
验证码 换一张
取 消