-1

I got this from web service and tried so many solution that I found in similar topics, but couldn't separate them to use in my code:

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"
        }
    ]
)

Please help me how can I use these information?

Omid
  • 21
  • 7

2 Answers2

0

You might be able to do something like:

$result = <webservice response>;

foreach ($result->getPropsListResult as $prop) {
   $prop['SalesPrice']; // To get salesprice
   $prop['PlantName']; // To get plant name
}
aljx0409
  • 252
  • 1
  • 7
  • I tried this code, but show nothing: $soapclient = new SoapClient('http://****.com/Pages/WebService/Keramat/KeramatWebService.asmx?wsdl'); try { $response = $soapclient->getCanboPropsList(); } catch (Exception $e) { echo($soapclient->__getLastResponse()); echo PHP_EOL; echo($soapclient->__getLastRequest()); } foreach ($response->getPropsListResult as $prop) { echo $prop['SalesPrice']; // To get salesprice echo "
    "; $prop['PlantName']; // To get plant name echo "

    "; }
    – Omid Apr 16 '20 at 05:13
  • right, so its from SOAP webservice. can you `print_r($response)` to see what you get? – aljx0409 Apr 16 '20 at 05:33
  • When I print_r($response), I got what I mentioned in question : stdClass Object ( [getPropsListResult] => [ { "id":16461, "Material":"1000001", ........ – Omid Apr 16 '20 at 05:38
0

The response that you received from the web service has json encoded payload. To use that pay load you will require to json_decode it first.

Here is how you can loop over the result items to access each individual item in the list.

$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...
}

Try using the code like this:

$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());
}
Ashish Patel
  • 442
  • 3
  • 8