[英]how to access items in this stdClass Object that is return from php/soap?
i am using osticket api and had developed this function to integrate osticket into my web application: 我正在使用osticket api,并开发了此功能以将osticket集成到我的Web应用程序中:
function ReadTicket($ticketID)
{
$osticket = new SoapClient('url');
$args = array(
'username' => 'someuser',
'password' => 'some pass',
'ticketID' => 1234);
try {
$result = $osticket->__call('ostTicket.getMessages',$args);
print_r( $result );
}
catch (SoapFault $e) {
throw $e;
}
}
and here is the result from print_r command: 这是print_r命令的结果:
Array ( [0] => stdClass Object ( [question] => stdClass Object ( [id] => 80 [created] => 2012-11-25T14:48:29-06:00 [name] => name [message] => body ) [answers] => Array ( [0] => stdClass Object ( [id] => 80 [created] => 2012-11-30T23:52:48-06:00 [name] => Admin Admin [message] => testttttttttt ) ) )
) Array ( [0] => stdClass Object ( [question] => stdClass Object ( [id] => 80 [created] => 2012-11-25T14:48:29-06:00 [name] => name [message] => body ) [answers] => Array ( [0] => stdClass Object ( [id] => 80 [created] => 2012-11-30T23:52:48-06:00 [name] => Admin Admin [message] => testttttttttt ) ) )
)
how to access the result and print out only id and message? 如何访问结果并仅打印ID和消息?
here is a reference to the soap call http://www.cyberde.nl/software-en-US/osticket-soap-mod/ostticket-getmessages/ 这是对Soap电话的参考http://www.cyberde.nl/software-zh-CN/osticket-soap-mod/ostticket-getmessages/
foreach($result[0]['answer'] as $ans)//one ore more answers
echo $ans['id']." '".$ans['message']."'<br/>";
it should be like $result[0]->question->id
or for multiple results 它应该像$result[0]->question->id
或多个结果
foreach($result as $r){
echo $r->question->id;
foreach($r->answers as $answer){
echo $answer->id;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.