我已成功使用PHP和SoapClient使用数组将请求传递给第三方API。通过从SoapClient转发请求传递给API的XML数据。
现在我遇到了< extendedData >所需的XML结构。我作为一个数组传递时遇到了麻烦;
<TypeID>int</TypeID>
<FooID>int</FooID>
<BarID>int</BarID>
<extendedData>
<Service_CreateFields>
<FieldName>my string 1</FieldName>
<FieldValue>my string 2</FieldValue>
<Comments>my string 3</Comments>
</Service_CreateFields>
<Service_CreateFields>
<FieldName>my string 4</FieldName>
<FieldValue>my string 5</FieldValue>
<Comments>my string 6</Comments>
</Service_CreateFields>
</extendedData>
我尝试过以下数组,但无法生成包含两个或更多&lt; Service_CreateFields &gt;
的XML请求$data = array(
"TypeID" => "11",
"FooID" => "22",
"BarID" => "33",
"extendedData" => array(
"Service_CreateFields" => array(
"FieldName" => "my string 1",
"FieldValue" => "my string 2",
"Comments" => "my string 3",
),
"Service_CreateFields" => array(
"FieldName" => "my string 4",
"FieldValue" => "my string 5",
"Comments" => "my string 6",
),
),
);
有没有人有这方面的经验?
答案 0 :(得分:1)
尝试将每个孩子包装在自己的数组中:
$data = array(
"TypeID" => "11",
"FooID" => "22",
"BarID" => "33",
"extendedData" => array(
"Service_CreateFields" => array(
array(
"FieldName" => "my string 1",
"FieldValue" => "my string 2",
"Comments" => "my string 3",
),
array(
"FieldName" => "my string 4",
"FieldValue" => "my string 5",
"Comments" => "my string 6",
)
)
)
);