parse data to array from an std object

193 views Asked by At

ive tried to get some data from mashape and then called it onto raw_body:

$data = $response -> raw_body;

i get this result:

{ "internalName": "jokb93", "dataVersion": 0, "acctId": 22059705, "name": "jokb93", "profileIconId": 31, "revisionDate": "Sep 14, 2013 3:36:46 PM", "revisionId": 0, "summonerId": 19355532, "summonerLevel": 30 }

then i try parsing it into seperate arrays for php to handle:

var json = '<? echo $data ?>',
    obj = JSON.parse(json);

alert(obj.internalName);

(Parse JSON in JavaScript?)

but it seems to end out blank?

thx for ur time hope u can figure this out :-D

1

There are 1 answers

0
Joachim Kiørbye Bertelsen On BEST ANSWER

ok so i got it now...

here is the api i call to:

    $response = Unirest::get(
  "https://community-league-of-legends.p.mashape.com/api/v1.0/".$server."/summoner/getSummonerByName/".$sumname."",
  array(
    "X-Mashape-Authorization" => "tLOVnMy2q8uGSEQHkG2kLquS1sgLfkso"
  ));

and to get the print of waht i want i do like this:

      $accid = $response->body->acctId;

  $intname = $response->body->internalName;

  echo $accid;
  echo "<br>";
  echo $intname;

this would work for anyone who needs to parse something down from their stdobject(if from mashape).

thx for the guidance guys.. :-D have a nice night... time to sleep now::

btw it echos this out then

22059705
jokb93

(depending on the values you put in)