dougongyou7364 2014-04-25 10:49
浏览 99
已采纳

如何从api请求中读取XML数据

I am making a call to some url : http://example.com/Service.asmx/getTodaysDiscussionForum which is xml data please see screenshot :enter image description here

$response = file_get_contents('http://103.1.115.87:100/Service.asmx/getTodaysDiscussionForum');

$response = new SimpleXMLElement($response);

print_r($response);exit;

it display following output :

SimpleXMLElement Object ( 
         [Table1] => Array ( [0] => SimpleXMLElement Object ( 
                                      [Id] => 1210 [Title] => Test Discussion, Dont Reply [CreatedDate] => 4/25/2014 10:42:49 AM 
                                      [Status] => Not Sent ) 
                             [1] => SimpleXMLElement Object ( 
                                      [Id] => 1182 [Title] => Negotiation Skills discussion [CreatedDate] => 4/25/2014 7:47:51 AM 
                                      [Status] => Not Sent )
                           )  
                        )

How can I store each data in a variables ?

I am new to this xml reading thanks in advance

  • 写回答

2条回答 默认 最新

  • dongpu7881 2014-04-25 10:56
    关注
    $xml = simplexml_load_string($xmlstring);
    $json = json_encode($xml); 
    $array = json_decode($json,TRUE);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?