2015-10-06 2 views
-3

Какой способ разбора XML-фид, который выглядит следующим образом:PHP Разбор XML с simplexml_load_file

<string xmlns="http://vs-social-feed/"> 
{ "response": "success", "message": "", "feed": 
[ 
{"SocialId":105,"Type":2,"Id":"202297433163449_956836567709528","Url":"https://www.facebook.com/vsmag/photos/a.209641845762341.52114.202297433163449/956836567709528/?type=3","Text":"Hold your tongue!\n\nStacy Martin by Ellen von Unwerth official for Vs. Magazine","Other":"\u003ca href=\"https://www.facebook.com/vsmag/photos/a.209641845762341.52114.202297433163449/956836567709528/?type=3\" target=\"_blank\"\u003e\u003cimg src=\"https://graph.facebook.com/956836567709528/picture/\" \" width=\"220\"\u003e\u003c/a\u003e","DateCreate":"\/Date(1444068001000)\/"}, 
{"SocialId":104,"Type":2,"Id":"202297433163449_956833817709803","Url":"https://www.facebook.com/vsmag/photos/a.209641845762341.52114.202297433163449/956833817709803/?type=3","Text":"Proper posture, ladies!\n\nThe always elegant, Christy Turlington Burns by Patrick Demarchelier","Other":"\u003ca href=\"https://www.facebook.com/vsmag/photos/a.209641845762341.52114.202297433163449/956833817709803/?type=3\" target=\"_blank\"\u003e\u003cimg src=\"https://graph.facebook.com/956833817709803/picture/\" \" width=\"220\"\u003e\u003c/a\u003e","DateCreate":"\/Date(1444075201000)\/"} 
] 
} 
</string> 

Я попытался с simplexml_load_file, file_get_contents, json_decode и JSon закодировать, но без удачи.

+0

мысль была XML, потому что поток упаковывается в <строка Xmlns = "HTTP: // Социально-корма /"> ... – andkjaer

+0

Вы будете иметь значение JSON из сначала XML, а затем декодировать его. – ThW

ответ

0

Это JSON данные не XML. PHP построил в json_decode() функция для анализа данных json.

Попробуйте этот код:

<?php 

$data = '{ "response": "success", "message": "", "feed":[{"SocialId":105,"Type":2,"Id":"202297433163449_956836567709528","Url":"https://www.facebook.com/vsmag/photos/a.209641845762341.52114.202297433163449/956836567709528/?type=3","Text":"Hold your tongue!\n\nStacy Martin by Ellen von Unwerth official for Vs. Magazine","Other":"\u003ca href=\"https://www.facebook.com/vsmag/photos/a.209641845762341.52114.202297433163449/956836567709528/?type=3\" target=\"_blank\"\u003e\u003cimg src=\"https://graph.facebook.com/956836567709528/picture/\" \" width=\"220\"\u003e\u003c/a\u003e","DateCreate":"/Date(1444068001000)/"},{"SocialId":104,"Type":2,"Id":"202297433163449_956833817709803","Url":"https://www.facebook.com/vsmag/photos/a.209641845762341.52114.202297433163449/956833817709803/?type=3","Text":"Proper posture, ladies!\n\nThe always elegant, Christy Turlington Burns by Patrick Demarchelier","Other":"\u003ca href=\"https://www.facebook.com/vsmag/photos/a.209641845762341.52114.202297433163449/956833817709803/?type=3\" target=\"_blank\"\u003e\u003cimg src=\"https://graph.facebook.com/956833817709803/picture/\" \" width=\"220\"\u003e\u003c/a\u003e","DateCreate":"/Date(1444075201000)/"}] }'; 
$obj = json_decode($data); 
echo "<pre>"; print_r($obj->feed); echo "</pre>"; 

?> 
Смежные вопросы