Guzzle 服务描述 json 数组
Guzzle service description json array
如何将 Guzzle 服务描述中的参数设置为 json 数组?
这是我尝试过但不起作用的方法:
$service_description = new Description([
'baseUri' => 'http://api.etrackerplus.com/api',
'operations' => [
'createOrder' => [
'httpMethod' => 'POST',
'uri' => 'api/stores/{store_id}/orders/new.json',
'responseModel' => 'getResponse',
'parameters' => [
'store_id' => [
'type' => 'string',
'location' => 'uri'
],
"order" => [// <== HERE!!!
"location" => "json",
"type" => "array"
]
]
]
],
'models' => [
'getResponse' => [
'type' => 'object',
'additionalProperties' => [
'location' => 'json'
]
]
]
]);
致电:
$response = $client->createOrder(['store_id' => '23',array( 'order'=>
array("order_number" => "1233"))]);
要发送的 json 正确 json 结构是这样的:
{
"order": {
"order_number": "97221"
}
}
您必须根据 JSON 架构验证规则编写 nested
定义。
我已经通过基于 XML 的请求完成了此操作。让我在基于 JSON 的数据中试试这个。希望这会有所帮助:
"order" => [
"location" => "json",
"type" => "object", // Because it's associative array in PHP but object in JS. Use "array" only if it's indexed array
"properties" => [ // define nested property order_number (by default type is string
"order_number" => [
"location" => "json",
],
],
],
如何将 Guzzle 服务描述中的参数设置为 json 数组? 这是我尝试过但不起作用的方法:
$service_description = new Description([
'baseUri' => 'http://api.etrackerplus.com/api',
'operations' => [
'createOrder' => [
'httpMethod' => 'POST',
'uri' => 'api/stores/{store_id}/orders/new.json',
'responseModel' => 'getResponse',
'parameters' => [
'store_id' => [
'type' => 'string',
'location' => 'uri'
],
"order" => [// <== HERE!!!
"location" => "json",
"type" => "array"
]
]
]
],
'models' => [
'getResponse' => [
'type' => 'object',
'additionalProperties' => [
'location' => 'json'
]
]
]
]);
致电:
$response = $client->createOrder(['store_id' => '23',array( 'order'=>
array("order_number" => "1233"))]);
要发送的 json 正确 json 结构是这样的:
{
"order": {
"order_number": "97221"
}
}
您必须根据 JSON 架构验证规则编写 nested
定义。
我已经通过基于 XML 的请求完成了此操作。让我在基于 JSON 的数据中试试这个。希望这会有所帮助:
"order" => [
"location" => "json",
"type" => "object", // Because it's associative array in PHP but object in JS. Use "array" only if it's indexed array
"properties" => [ // define nested property order_number (by default type is string
"order_number" => [
"location" => "json",
],
],
],