无法实例化 Json 中类型的值
Can not instantiate value of type in Json
我正在尝试 post 一个已经 json 编码的数组。
在 JSON 串上
{"name":"q_4","label":"Are you ...","description":"Are you ...","groupName":"Questionnaire","type":"enumeration","fieldType":"select","formField":true,"options":["Male","Female"]}
我收到错误
Invalid input JSON on line 1, column 163: Can not instantiate value of type [simple type, class com.hubspot.inbounddb.properties.views.OptionView] from String value ('Male'); no single-String constructor/factory method
json 字符串在 json lint 上测试时通过。
我使用下面的代码 post 我的 json。
$jsonData = json_encode($jdata);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $createType);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData))
);
$result = curl_exec($ch);
您必须将选项作为带有标签和值的对象数组传递,如下所示:
"options": [
{
label: "Male",
value: "male"
},
{
label: "Female",
value: "female"
}
]
您可以在此处查看枚举字段(复选框)的示例:https://developers.hubspot.com/docs/methods/contacts/v2/create_contacts_property
我正在尝试 post 一个已经 json 编码的数组。
在 JSON 串上
{"name":"q_4","label":"Are you ...","description":"Are you ...","groupName":"Questionnaire","type":"enumeration","fieldType":"select","formField":true,"options":["Male","Female"]}
我收到错误
Invalid input JSON on line 1, column 163: Can not instantiate value of type [simple type, class com.hubspot.inbounddb.properties.views.OptionView] from String value ('Male'); no single-String constructor/factory method
json 字符串在 json lint 上测试时通过。
我使用下面的代码 post 我的 json。
$jsonData = json_encode($jdata);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $createType);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData))
);
$result = curl_exec($ch);
您必须将选项作为带有标签和值的对象数组传递,如下所示:
"options": [
{
label: "Male",
value: "male"
},
{
label: "Female",
value: "female"
}
]
您可以在此处查看枚举字段(复选框)的示例:https://developers.hubspot.com/docs/methods/contacts/v2/create_contacts_property