将作为对象 std 从 Web 服务接收的分开 class
Separate received from web-service as object std class
我从网络服务中得到这个并尝试了很多我在类似主题中找到的解决方案,但无法将它们分开以在我的代码中使用:
stdClass Object (
[getPropsListResult] => [
{
"id":16461,
"Material":"1000001",
"SalesDescription":"product1",
"Plnt":"1339",
"PlantName":"WAREHOUSE1",
"SalesPrice":"15000"
},
{
"id":16462,
"Material":"1000001",
"SalesDescription":" product2",
"Plnt":"1018",
"PlantName":"WAREHOUSE2",
"SalesPrice":"15000"
},
{
"id":16463,
"Material":"1000002",
"SalesDescription":" product3",
"Plnt":"1339",
"PlantName":"WAREHOUSE1",
"SalesPrice":"22000"
},
{
"id":32920,
"Material":"1072941",
"SalesDescription":"product4",
"Plnt":"1018",
"PlantName":" WAREHOUSE1",
"SalesPrice":"0"
}
]
)
请帮助我如何使用这些信息?
您或许可以执行以下操作:
$result = <webservice response>;
foreach ($result->getPropsListResult as $prop) {
$prop['SalesPrice']; // To get salesprice
$prop['PlantName']; // To get plant name
}
您从网络服务收到的响应具有 json encoded
负载。要使用该有效载荷,您需要先 json_decode
它。
以下是循环遍历结果项以访问列表中每个单独项的方法。
$itemList = json_decode($webServiceResponse->getPropsListResult);
foreach ($itemList as $item) {
// access props like this
echo $item->id;
echo $item->Material;
echo $item->SalesDescription;
// and so on...
}
尝试使用如下代码:
$soapclient = new SoapClient('http://****.com/Pages/WebService/Keramat/KeramatWebService.asmx?wsdl');
try {
$response = $soapclient->getCanboPropsList();
$itemList = json_decode($response->getPropsListResult);
foreach ($itemList as $item) {
// access props like this
echo $item->id;
echo $item->Material;
echo $item->SalesDescription;
// and so on...
}
}
catch(Exception $e) {
echo ($soapclient->__getLastResponse());
echo PHP_EOL;
echo ($soapclient->__getLastRequest());
}
我从网络服务中得到这个并尝试了很多我在类似主题中找到的解决方案,但无法将它们分开以在我的代码中使用:
stdClass Object (
[getPropsListResult] => [
{
"id":16461,
"Material":"1000001",
"SalesDescription":"product1",
"Plnt":"1339",
"PlantName":"WAREHOUSE1",
"SalesPrice":"15000"
},
{
"id":16462,
"Material":"1000001",
"SalesDescription":" product2",
"Plnt":"1018",
"PlantName":"WAREHOUSE2",
"SalesPrice":"15000"
},
{
"id":16463,
"Material":"1000002",
"SalesDescription":" product3",
"Plnt":"1339",
"PlantName":"WAREHOUSE1",
"SalesPrice":"22000"
},
{
"id":32920,
"Material":"1072941",
"SalesDescription":"product4",
"Plnt":"1018",
"PlantName":" WAREHOUSE1",
"SalesPrice":"0"
}
]
)
请帮助我如何使用这些信息?
您或许可以执行以下操作:
$result = <webservice response>;
foreach ($result->getPropsListResult as $prop) {
$prop['SalesPrice']; // To get salesprice
$prop['PlantName']; // To get plant name
}
您从网络服务收到的响应具有 json encoded
负载。要使用该有效载荷,您需要先 json_decode
它。
以下是循环遍历结果项以访问列表中每个单独项的方法。
$itemList = json_decode($webServiceResponse->getPropsListResult);
foreach ($itemList as $item) {
// access props like this
echo $item->id;
echo $item->Material;
echo $item->SalesDescription;
// and so on...
}
尝试使用如下代码:
$soapclient = new SoapClient('http://****.com/Pages/WebService/Keramat/KeramatWebService.asmx?wsdl');
try {
$response = $soapclient->getCanboPropsList();
$itemList = json_decode($response->getPropsListResult);
foreach ($itemList as $item) {
// access props like this
echo $item->id;
echo $item->Material;
echo $item->SalesDescription;
// and so on...
}
}
catch(Exception $e) {
echo ($soapclient->__getLastResponse());
echo PHP_EOL;
echo ($soapclient->__getLastRequest());
}