我不知道如何获取列表中的数据
$client = new SoapClient("http://services.blabla.com/blabla.asmx?WSDL");
$vec = array(
"DealerID"=>"0000",
"Password"=>"00000000000000"
);
$response = $client->GetAllProduct($vec);
print_r($response);
输出:
<Product diffgr:id="Product1" msdata:rowOrder="0">
<ID>744</ID>
<ProductCode>CF920</ProductCode>
<ProductName>Test Product</ProductName>
<CarName>Test Product</CarName>
<Remark>Test Product</Remark>
<ImagePath>https://www.blabla.com/Images/ShowImages/product-medium/blabla.jpg</ImagePath>
<Status>true</Status>
</Product>
ProductName ??
foreach($response as $pro){
echo $pro->ProductName;
}
错误:未定义的属性:stdClass :: $ ProductName 如何找到产品名称?
答案 0 :(得分:0)
要像XML一样访问,您可以使用simplexml进行php
示例:
$xmlstr = <<<XML
<Product diffgr:id="Product1" msdata:rowOrder="0">
<ID>744</ID>
<ProductCode>CF920</ProductCode>
<ProductName>Test Product</ProductName>
<CarName>Test Product</CarName>
<Remark>Test Product</Remark>
<ImagePath>https://www.blabla.com/Images/ShowImages/product-medium/blabla.jpg</ImagePath>
<Status>true</Status>
</Product>
XML;
$test = new SimpleXMLElement($xmlstr);
echo $test->ProductName;
答案 1 :(得分:0)
stdClass Object
(
[any] =>
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Product" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Product">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" msdata:ReadOnly="true" msdata:AutoIncrement="true" type="xs:int"/>
<xs:element name="ProductCode" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ProductName" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="200"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CariName" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="250"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Remark" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="2147483647"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ImagePath" msdata:ReadOnly="true" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="161"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Status" type="xs:boolean" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DocumentElement xmlns="">
<Product diffgr:id="Product1" msdata:rowOrder="0">
<ID>74</ID>
<ProductCode>CF920</ProductCode>
<ProductName>Test Product</ProductName>
<CarName>Test Product</CarName>
<Remark>Test Product</Remark>
<ImagePath>https://www.blabla.com/Images/ShowImages/product-medium/blabla.jpg</ImagePath>
<Status>true</Status>
</Product>
答案 2 :(得分:0)
我希望我的解决方案能回答你的问题
1-首先确保你的xsd是这样的
<types>
<xsd:schema targetNamespace="http://localhost/app_dev.php/product">
<xsd:complexType name="Product"><xsd:all><xsd:element name="id" type="xsd:int" nillable="true"/><xsd:element name="ProductCode" type="xsd:string" nillable="true"/><xsd:element name="ProductName" type="xsd:string" nillable="true"/><xsd:element name="CarName" type="xsd:string" nillable="true"/><xsd:element name="ImagePath" type="xsd:string" nillable="true"/></xsd:all></xsd:complexType><xsd:complexType name="ArrayOfProduct"><xsd:complexContent><xsd:restriction base="soap-enc:Array"><xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="tns:Product[]"/></xsd:restriction></xsd:complexContent></xsd:complexType></xsd:schema>
</types>
2秒,您的soap服务器服务必须返回一个产品数组
/**
* @return MT\Solution\SoapModel\Product[]
*/
public function getProductss(){
$products= $this->productRepository->getAll();
return $products;
}
3-在您的客户电话中,请执行此操作
new SoapClient(
'wsdl.wsdl',
array(
'features' => **SOAP_SINGLE_ELEMENT_ARRAYS**));
在数组中包含单个产品元素。