【发布时间】:2016-10-16 13:10:12
【问题描述】:
我需要发送这个数组:
$nums = [
[
'title' => 'How to create a simple module',
'summary' => 'The summary',
'description' => 'The description',
'created_at' => date('Y-m-d H:i:s'),
'status' => 1
],
[
'title' => 'Create a module with custom database table',
'summary' => 'The summary',
'description' => 'The description',
'created_at' => date('Y-m-d H:i:s'),
'status' => 1
]
];
通过 JSON 使用 curl 我试试这个:
{"nums":
{
{
"title":"How to create a simple module",
"summary":"The summary",
"description":"The description",
"created_at":"2016-10-16 12:51:26",
"status":1
},
{
"title":"How to create a simple module",
"summary":"The summary",
"description":"The description",
"created_at":"2016-10-16 12:51:26",
"status":1
}
}
}
但我得到一个解码错误。
当我发送只是
{"nums":
{
{
"title":"How to create a simple module",
"summary":"The summary",
"description":"The description",
"created_at":"2016-10-16 12:51:26",
"status":1
}
}
}
它有效,我得到了
Array(
[title] => How to create a simple module
[summary] => The summary
[description] => The description
[created_at] => 2016-10-16 12:51:26
[status] => 1)
但这不是我需要的。
据我了解,当我通过 curl 发送 JSON 数组时,我不能使用“[]”括号,因为当我尝试发送时
{"nums":
[
{
"title":"How to create a simple module",
"summary":"The summary",
"description":"The description",
"created_at":"2016-10-16 12:51:26",
"status":1
},
{
"title":"How to create a simple module",
"summary":"The summary",
"description":"The description",
"created_at":"2016-10-16 12:51:26",
"status":1
}
]}
我有例外:
Next Exception: Report ID: webapi-58037ddbaccd0; Message: Notice: Array to string conversion in /home/workuser/Projects/magentov/vendor/magento/framework/Reflection/TypeProcessor.php on line 505 in /home/workuser/Projects/magentov/vendor/magen$
Stack trace:
#0 /home/workuser/Projects/magentov/vendor/magento/framework/Webapi/ErrorProcessor.php(139): Magento\Framework\Webapi\ErrorProcessor->_critical(Object(Exception))
#1 /home/workuser/Projects/magentov/vendor/magento/module-webapi/Controller/Rest.php(219): Magento\Framework\Webapi\ErrorProcessor->maskException(Object(Exception))
#2 /home/workuser/Projects/magentov/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(37): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#3 /home/workuser/Projects/magentov/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#4 /home/workuser/Projects/magentov/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#5 /home/workuser/Projects/magentov/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#6 {main} [] []
请帮忙。
【问题讨论】: