這只是正常PHP的echo價值將無法正常工作
<?php echo $response->user->last_game; ?>
但這並不
$oscore=$response->user->current_game;
我怎樣才能獲得$ oscore等於從這個腳本拉到該值:
private function clean_dirty_response($object)
{
// The final object
$final_object = new StdClass();
// Convert the XML to an object
$object = simplexml_load_string($object);
// Now that we've converted the XML to an object we can start shifting things around
$final_object->user->membership_status = (string)$object->AccountStatus;
$final_object->user->last_game = str_replace(' ',' ', (string)$object->PresenceInfo->Info); // For some reason there's some extra whitespace that needs to be removed
$final_object->user->current_game = str_replace(' ',' ', (string)$object->PresenceInfo->Info2); // For some reason there's some extra whitespace that needs to be removed
$final_object->user->last_seen = (string)$object->PresenceInfo->LastSeen;
$final_object->user->online = (string)$object->PresenceInfo->Online;
$final_object->user->status_text = (string)$object->PresenceInfo->StatusText;
$final_object->user->title = (string)$object->PresenceInfo->Title;
$final_object->user->gamertag = (string)$object->Gamertag;
$final_object->user->profile_url = (string)$object->ProfileUrl;
// Jezus christ, why capitalize every freaking word? Just use lowercase next time you damn API!
$final_object->user->profile_picture = (string)$object->TileUrl;
$final_object->user->avatar = 'http://avatar.xboxlive.com/avatar/' . str_replace(' ', '%20', $final_object->user->gamertag) . '/avatar-body.png';
$final_object->user->country = (string)$object->Country;
$final_object->user->reputation = (int)$object->Reputation;
$final_object->user->bio = (string)$object->Bio;
$final_object->user->location = (string)$object->Location;
$final_object->user->reputation_image = (string)$object->ReputationImageUrl;
$final_object->user->gamerscore = (string)$object->GamerScore;
$final_object->user->zone = (string)$object->Zone;
// Now it's time to clean the RecentGames part
$final_object->recent_games = array();
$i = 0;
// Loop through each game and clean it up
foreach ($object->RecentGames->XboxUserGameInfo as $recent_game)
{
$obj = new stdClass();
$obj->name = (string)$recent_game->Game->Name;
$obj->achievements = (int)$recent_game->Achievements;
$obj->total_achievements = (int)$recent_game->Game->TotalAchievements;
$obj->gamerscore = (int)$recent_game->GamerScore;
$obj->total_gamerscore = (int)$recent_game->Game->TotalGamerScore;
$obj->thumb_32 = (string)$recent_game->Game->Image32Url;
$obj->thumb_64 = (string)$recent_game->Game->Image64Url;
// Format the date
$raw_date = (string)$recent_game->LastPlayed;
$raw_date = explode('T', $raw_date);
$date = $raw_date[0];
// Time
$raw_time = $raw_date[1];
$raw_time = explode('+', $raw_time);
$time = $raw_time[0];
// Offset
$offset = $raw_time[1];
$obj->last_played = array('date' => $date, 'time' => $time, 'offset' => $offset);
$obj->details_url = (string)$recent_game->DetailsURL;
$final_object->recent_games[$i] = $obj;
// counter + 1
++$i;
}
return $final_object;
}
沒有看到更多的代碼,這是相當難以給出一個答案。 – kiamlaluno 2010-07-20 16:21:33
完整代碼添加 – 2010-07-20 16:23:26
您應該初始化'$ final_object-> user',然後才能使用它。 '$ final_object-> user = new stdClass()'應該足夠了。 – kiamlaluno 2010-07-20 16:26:04