Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php JMS序列化程序反序列化嵌套对象_Php_Json_Symfony_Serialization - Fatal编程技术网

Php JMS序列化程序反序列化嵌套对象

Php JMS序列化程序反序列化嵌套对象,php,json,symfony,serialization,Php,Json,Symfony,Serialization,我正在使用: 用于反序列化json对象。 目前我有: /** * @param int $id * @return Customer * @throws \Http\Client\Exception */ public function get(int $id): Customer { $response = $this->client->get('/customers/' . $id); $data = json_encode(json_decode(

我正在使用:

用于反序列化json对象。 目前我有:

/**
 * @param int $id
 * @return Customer
 * @throws \Http\Client\Exception
 */
public function get(int $id): Customer
{
    $response = $this->client->get('/customers/' . $id);

    $data = json_encode(json_decode(
        $response->getBody()->getContents()
    )->data->attributes);

    return $this
        ->serializer
        ->deserialize($data, Customer::class, 'json');
}
我在这里收到的json如下所示:

   {
    "data": {
            "type": "customer",
            "id": "4356456",
            "links": {
                    "self":"https:\/\/api.ecurring.com\/customers\/345656"
            },
            "attributes": {
                    "gender": "m",
            "first_name": "Laurens"
        }
    }
 $data = json_encode(json_decode(
            $response->getBody()->getContents()
        )->data->attributes);
是否可以告诉JMS它应该自动从
data->attributes
开始,而不是像这样做:

   {
    "data": {
            "type": "customer",
            "id": "4356456",
            "links": {
                    "self":"https:\/\/api.ecurring.com\/customers\/345656"
            },
            "attributes": {
                    "gender": "m",
            "first_name": "Laurens"
        }
    }
 $data = json_encode(json_decode(
            $response->getBody()->getContents()
        )->data->attributes);

您可以检查排除策略

阅读文档,它真的很有帮助


您可以检查排除策略

阅读文档,它真的很有帮助