[解决]我没有看到对象数据,因为我没有在类Credential中实现JsonSerializable
使用PHP创建对象时遇到问题。 我调用API并毫无问题地收到响应,但是当我尝试将API的值放入我的对象($ credential = new Credential)时,该对象总是返回一个空的Credential(例如:{})。
我尝试在对象内部手动插入数据,但响应始终相同。 当我仅显示$ reqValue-> id,$ reqValue-> guid的数据时...这些数据是正确的。 我使用Visual Studio,当我使用断点查看函数结果时,它向我显示了一个带有数据的凭据对象。
public function superSearch($containText, $searchOperator){
//Params to call the API
$param = [
DEFAULT_IDENTIFIER => $this->guidv4(),
"containText" => $containText,
"searchOperator" => $searchOperator
];
//Prepare the call of the API
$api = new Manager();
//Call the API with params
$req = $api->getRequest(WEBSERVICE["LibAuth"],
CredentialManager::SERVICE_NAME_READ,
"superSearch", $param)
->response;
//Tabs for result
$result = [];
foreach($req as $reqKey => $reqValue){
//Problem here the $credential is always with empty Object {}
$credential = new Credential($reqValue->id,
$reqValue->guid,
$reqValue->name,
$reqValue->flagDisplay);
//Create a dictionnary with a key but had an empty Object
$result[$reqValue->id] = $credential;
}
return $result;
}
并知道凭证对象的类别。
class Credential
{
private $id;
private $guid;
private $name;
private $flagDisplay;
public function __construct($id, $guid, $name, $flagDisplay)
{
$this->id = $id;
$this->guid = $guid;
$this->name = $name;
$this->flagDisplay = $flagDisplay;
}
我不知道我的问题在哪里,你能帮我吗?
有
的归还$req : [
{"flagDisplay":1,
"guid":"07cb6970-9eb8-432e-b55f-21c2ee705d9e",
"id":1088,
"name":"ManagerTest"
},{
"flagDisplay":1,
"guid":"5fed7798-89dc-4c30-95cc-e917c382a5df",
"id":1069,
"name":"testManager1"
}
]