开发者

Web service Array problem

开发者 https://www.devze.com 2023-03-14 09:56 出处:网络
I have this web service http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|Nro7dAY411DJRn7E8zB6MOXHjq8

I have this web service http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|Nro7dAY411DJRn7E8zB6MOXHjq8

And I'm having problems catching some values like:

clubId, clubName, clubLogo, relationType, and dateAdded. I just don't know how to handle the array. My code:

<?php
function getUserInfo() {
$json = file_get_contents('http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|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['userin开发者_开发百科fclubName'][0] . '<br />'; 
echo 'LogoClube: ' . $_SESSION['userinfclubLogo'][0] . '<br />';
echo 'RelationType: ' . $_SESSION['userinfrelationType'][0] . '<br />';
echo 'DataAdicionado: ' . $_SESSION['userinfdateAdded'][0] . '<br />';

?>


And if there is only one value for each key of session then

<?php
function getUserInfo() {
   $json = file_get_contents('http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|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 />';


Be careful,there's more than one club in clubs, so you'll need to do something like this :

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

精彩评论

暂无评论...
验证码 换一张
取 消