2011-06-22 138 views
0

我有這個Web服務http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-1000010|Nro7dAY411DJRn7E8zB6MOXHjq8Web服務陣列問題

,我有趕上像一些價值觀問題:

clubId,clubName,clubLogo,relationType和dateAdded。 我只是不知道如何處理數組。 我的代碼:

<?php 
function getUserInfo() { 
$json = file_get_contents('http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-1000010|Nro7dAY411DJRn7E8zB6MOXHjq8'); 
    $data = json_decode($json, TRUE); 
    $v= $data['data']; 
    $_SESSION['userinfid'][] = $v['id']; 
    $_SESSION['userinfnickname'][] = $v['nickname']; 
    $_SESSION['userinfvisibility'][] = $v['visibility']; 
    $_SESSION['userinffirstname'][] = $v['first_name']; 
    $_SESSION['userinflastname'][] = $v['last_name']; 
    $_SESSION['userinfgender'][] = $v['gender']; 
    $_SESSION['userinfdialect'][] = $v['dialect']; 
    $_SESSION['userinfstatus'][] = $v['status']; 
    $_SESSION['userinfadmissiondate'][] = $v['admission_date']; 
    $_SESSION['userinflastaccess'][] = $v['last_access']; 
    $_SESSION['userinfusername'][] = $v['username']; 
    $_SESSION['userinfpoints'][] = $v['points']; 
    $_SESSION['userinfranking'][] = $v['ranking']; 
    $_SESSION['userinfsessionID'][] = $v['sessionID']; 
    $_SESSION['userinfpublicProfile'][] = $v['publicProfile']; 
    $_SESSION['userinfemail'][] = $v['email']; 
    $_SESSION['userinfmobile'][] = $v['mobile']; 
    $_SESSION['userinfimageURL'][] = $v['imageURL']; 
    $_SESSION['userinfclubURL'][] = $v['clubURL']; 
    $_SESSION['userinfcontact'][] = $v['contacts']['contact']; 
    $_SESSION['userinfcontactType'][] = $v['contacts']['contactType']; 
    $_SESSION['userinfisdefault'][] = $v['contacts']['is_default']; 
    $_SESSION['userinfclubId'][] = $v['clubs']['clubId']; 
    $_SESSION['userinfclubName'][] = $v['clubs']['clubName']; 
    $_SESSION['userinfclubLogo'][] = $v['clubs']['clubLogo']; 
    $_SESSION['userinfrelationType'][] = $v['clubs']['relationType']; 
    $_SESSION['userinfdateAdded'][] = $v['clubs']['dateAdded']; 
} 
getUserInfo(); 

echo 'IDClube: ' . $_SESSION['userinfclubId'][0] . '<br />'; 
echo 'NomeClube: ' . $_SESSION['userinfclubName'][0] . '<br />'; 
echo 'LogoClube: ' . $_SESSION['userinfclubLogo'][0] . '<br />'; 
echo 'RelationType: ' . $_SESSION['userinfrelationType'][0] . '<br />'; 
echo 'DataAdicionado: ' . $_SESSION['userinfdateAdded'][0] . '<br />'; 

?> 

回答

1

小心價值,有一個在俱樂部不止一個俱樂部,所以你需要做的事情像這樣:

foreach ($v['clubs'] as $value) { 
    $_SESSION['userinfclubId'][] = $value['clubId']; 
    $_SESSION['userinfclubName'][] = $value['clubName']; 
    $_SESSION['userinfclubLogo'][] = $value['clubLogo']; 
    $_SESSION['userinfrelationType'][] = $value['relationType']; 
    $_SESSION['userinfdateAdded'][] = $value['dateAdded']; 
} 
+0

我很困惑,這只是爲了俱樂部陣列?和其他會話變量?謝謝大家的幫助 –

+1

這隻適用於俱樂部陣列,其他已經解碼的數據。 –

3

而且如果只有一個會話的每個鍵,然後

<?php 
function getUserInfo() { 
    $json = file_get_contents('http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-1000010|Nro7dAY411DJRn7E8zB6MOXHjq8'); 
    $data = json_decode($json, TRUE); 
    $v= $data['data']; 
    foreach($v as $key => $value) 
    { 
     $_SESSION['userinf'.$key] = $value; 
    } 
} 



getUserInfo(); 
echo 'IDClube: ' . $_SESSION['userinfclubs']['clubId'] . '<br />'; 
echo 'NomeClube: ' . $_SESSION['userinfclubs']['clubName'] . '<br />'; 
echo 'LogoClube: ' . $_SESSION['userinfclubs']['clubLogo'] . '<br />'; 
echo 'RelationType: ' . $_SESSION['userinfclubs']['relationType'] . '<br />'; 
echo 'DataAdicionado: ' . $_SESSION['userinfclubs']['dateAdded'] . '<br />'; 
+1

多數民衆贊成正是我thought..100%更優雅和清潔 –

+0

不工作,我必須做一些錯誤的。只是給我 IDClube:Array –

+0

必須給IClube:1821c879-8c67-11e0-8250-000c29b481aa –