Я работаю с XML-файлом, который я пытаюсь разобрать в формате json, а затем декодировать в массив. Я сделал это, главным образом, используя встроенный simplexml_load_string
, а затем json_encode
. Проблема заключается в том, что при вызове simplexml_load_string
xml не полностью сохраняется. Похоже, что дочерние узлы для video
показаны как object(stdClass)
. Как я могу получить все значения xml-файла? Ссылка на XMLsimplexml_load_string - дочерние узлы, не показывающие
Код:
$xml = simplexml_load_string(file_get_contents('http://foxsoccer2go.mobilefeeds.performgroup.com/fox/api/videos.xml/channel/home'));
$json = json_encode($xml);
Результат:
["results"]=>
object(stdClass)#183 (4) {
["previousPage"]=>
object(stdClass)#184 (1) {
["@attributes"]=>
object(stdClass)#185 (1) {
["exists"]=>
string(5) "false"
}
}
["nextPage"]=>
string(1) "2"
["total"]=>
string(2) "40"
["resultList"]=>
object(stdClass)#186 (1) {
["video"]=>
array(20) {
[0]=>
object(stdClass)#187 (7) {
["@attributes"]=>
object(stdClass)#188 (2) {
["id"]=>
string(7) "2329124"
["type"]=>
string(3) "960"
}
["description"]=>
object(stdClass)#189 (0) {
}
["created"]=>
string(25) "2015-02-18 04:04:52 +0000"
["duration"]=>
string(2) "86"
["images"]=>
object(stdClass)#190 (2) {
["image"]=>
object(stdClass)#191 (1) {
["@attributes"]=>
object(stdClass)#192 (3) {
["id"]=>
string(8) "13503818"
["width"]=>
string(3) "100"
["height"]=>
string(3) "100"
}
}
["thumbnail"]=>
object(stdClass)#193 (1) {
["@attributes"]=>
object(stdClass)#194 (3) {
["id"]=>
string(8) "13503819"
["width"]=>
string(3) "372"
["height"]=>
string(3) "210"
}
}
}
["videoFiles"]=>
object(stdClass)#195 (1) {
["file"]=>
object(stdClass)#196 (1) {
["@attributes"]=>
object(stdClass)#197 (3) {
["id"]=>
string(8) "14704560"
["formatId"]=>
string(3) "400"
["uploaded"]=>
string(4) "true"
}
}
}
["categories"]=>
object(stdClass)#198 (1) {
["category"]=>
string(21) "UEFA Champions League"
}
}
тогда не кодировать/декодировать его, просто разобрать 'SimpleXMLElement's, как это. – Ghost
@Ghost, я пробовал делать просто «SimpleXMLElement», как без кодирования/декодирования, и он до сих пор не показывает дочерние узлы. Например, 'description' показывает' object (SimpleXMLElement) # 450 (0) {} ' – MaryCoding
Я не знаю, что делать, но он определенно работает http://codepad.viper-7.com/LK1ULi – Ghost