哈希类型的属性“#/”与一个或多个所需架构不匹配

Pau*_*ert 6 php json

我正在尝试通过 API 将用户添加到列表中。但是,我收到此错误返回:

{"errors":[{"code":"parsing_error","message":"JSON parsing error: The property '#/' of type Hash did not match one or more of the required schemas"}]}
Run Code Online (Sandbox Code Playgroud)

这就是我要发送的内容:{"subscribers":{"email":"me@gmail.com"}}

这是 PHP 代码:

$subscriberInfo = [
    'subscribers' => array (
        'email' => $email
    )
];

$encoded = json_encode($subscriberInfo);
Run Code Online (Sandbox Code Playgroud)

JSON的结构有问题吗?

Ale*_*lex 4

这不是文档中描述的格式。subscribers应该是一个数组,而不是一个对象:

$subscriberInfo = [
    'subscribers' => [
        ['email' => $email]
    ]
];

$encoded = json_encode($subscriberInfo);
Run Code Online (Sandbox Code Playgroud)