你好,我得到了溢出游戏xml中的游戏。我设法将它转换为数组,但又出现了一个问题,问题是我想要得到的字符串位于数组内部,或者一个1节点的xml .I属性不能获得该属性。
我想要得到属性。
溢出游戏网站:http://publishers.spilgames.com/rss-3?limit=100&format=xml&category=Action
我到目前为止的代码是:
<?php
$xml = simplexml_load_string(file_get_contents('http://publishers.spilgames.com/rss-3?limit=100&format=xml&category=Action')); /* Get the xml */
$json = json_encode($xml);
$games = json_decode($json); /* Make it an array */
$game = $games->entries->entry;
foreach($game as $entry) { /* Each game information */
echo $entry->title;
echo $entry->id;
echo $entry->description;
echo $entry->category;
echo $entry->subcategory;
echo $entry->technology;
echo $entry->player->url;;
echo $entry->thumbnails->small->url; /* Problems starts here */
/* Because the thumbnails has 3 child but the info is inside of each child */
}
?>我在溢出游戏中得到的是xml而不是json,因为我不知道json是如何工作的。
发布于 2014-04-09 19:40:28
如果我是您,我将学习JSON是如何工作的,因为它将使您的生活更轻松:
<?php
$json = file_get_contents('http://publishers.spilgames.com/rss-3?limit=100&format=json&category=Action');
$data = json_decode($json);
foreach ($data->entries as $entry) {
echo $entry->title . "\n";
echo $entry->id . "\n";
echo $entry->description . "\n";
echo $entry->category . "\n";
echo $entry->subcategory . "\n";
echo $entry->technology . "\n";
echo $entry->thumbnails->small . "\n";
echo $entry->thumbnails->medium . "\n";
echo $entry->thumbnails->large . "\n";
}
?>https://stackoverflow.com/questions/22970420
复制相似问题