Rusty Nail Posted September 30, 2008 Share Posted September 30, 2008 I have the following data coming back to me from a webservice call. On the server side it's returned as a list of newsentry. Doing a var_dump produces : object(stdClass)#3 (1) { ["NewsEntry"]=> array(2) { [0]=> object(stdClass)#4 (7) { ["Id"]=> int(1) ["NewGUID"]=> string(36) "32227d20-a987-4b28-9cc5-dce1c4c22994" ["Title"]=> string(9) "New Title" ["Intro"]=> string(17) "Here is the intro" ["Body"]=> string(30) "The body is this Hi Man" ["EventDate"]=> string(19) "2008-09-30T00:00:00" ["CreatedDate"]=> string(19) "2008-09-30T00:00:00" } [1]=> object(stdClass)#5 (7) { ["Id"]=> int(2) ["NewGUID"]=> string(36) "fff5574a-0863-44d2-a1e2-895f293ad3b2" ["Title"]=> string(9) "New Title" ["Intro"]=> string(17) "Here is the intro" ["Body"]=> string(30) "The body is this Hi Man" ["EventDate"]=> string(19) "2008-09-30T00:00:00" ["CreatedDate"]=> string(19) "2008-09-30T00:00:00" } } } What I am trying to do is to parse these into objects I can then iterate though. Essentially (psuedo code) foreach($entry in $responseObj) { printf("Title : " . $entry->Title; } I've also included what the PHP SoapClient outputs when I execute the following : $types = $soapClient->__getTypes(); Here is the output for what I am getting back : Array ( [0] => struct GetNewsEvents { } [1] => struct GetNewsEventsResponse { ArrayOfNewsEntry GetNewsEventsResult; } [2] => struct ArrayOfNewsEntry { NewsEntry NewsEntry; } [3] => struct NewsEntry { int Id; guid NewGUID; string Title; string Intro; string Body; dateTime EventDate; dateTime CreatedDate; } Please HELP.. the project is due by this afternoon... Thanks Link to comment https://forums.phpfreaks.com/topic/126462-solved-need-help-parsing-this-object/ Share on other sites More sharing options...
Rusty Nail Posted September 30, 2008 Author Share Posted September 30, 2008 Well I finally figured this out... ini_set("soap.wsdl_cache_enabled", "0"); // init the soap client $soapClient = new SoapClient("http://pdc01/SmartClientDemo/Service.asmx?WSDL"); $response = $soapClient->GetNewsEvents(); $list = $response->GetNewsEventsResult->NewsEntry; foreach ($list as &$value) { printf("<p><b>" . $value->Title . "</b> " . $value->EventDateDisplay . "<br>" . $value->Intro . "</p>"); } Produces the following : Big Stuff 10/1/2008 Idocms lives New Title 9/30/2008 Here is the intro So I lucked into figuring out myself. My first attempt at doing php.. seems pretty cool.. for FYI A had to create a php page that would consume data from a ASP.NET webservice for a client. The complexity came from the webservice returning List<NewsEntry> (a generic list collection). Anyway.. got it working if you would like an example just pm me Thanks Link to comment https://forums.phpfreaks.com/topic/126462-solved-need-help-parsing-this-object/#findComment-653954 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.