2016-04-10 11 views
0

ProblemFetch JSON-Daten, wikimedia

ich diesen JSON Inhalt haben, die ich von wikimedia API im JSON-Format einsehen. Ich möchte die Daten unter [*] diese extrahieren. Obwohl ich vor dem Aufruf der Seiten-ID nicht weiß, kann ich die Seitenkennung nicht in der Mitte verwenden. Auch ich nicht, wie man Astrologie (*) übergibt. Ich habe folgenden Code zum Abrufen der Daten verwendet, aber einen Fehler erhalten.

Ich werde wirklich jede Hilfe oder Anleitung zu schätzen wissen.

-Code

$api_data->query->pages->revisions[0]->['*']; 

JSON

stdClass Object 
(
    [batchcomplete] => 
    [query] => stdClass Object 
     (
      [pages] => stdClass Object 
       (
        [27000] => stdClass Object 
         (
          [pageid] => 27000 
          [ns] => 0 
          [title] => Patna 
          [revisions] => Array 
           (
            [0] => stdClass Object 
             (
              [contentformat] => text/x-wiki 
              [contentmodel] => wikitext 
              [*] => ==Understand== 
The ancient name of Patna was 'Pataliputra' and it was the capital of the Maurya and Gupta empires. Located at the site where Patna is today, the ancient city of Patliputra, with a glorious period of history spanning a thousand years (500BC-400AD), saw the rise and fall of India's first major kingdoms. 

Lying along the banks of the Ganges River, Patna is surrounded by important religious centers for the Buddhists, Sikhs and Jains. This city has been home to two great religions, Buddhism and Jainism, and myriad dynasties from ancient to modern times. 
             ) 

           ) 

         ) 

       ) 

     ) 

) 
+2

'$ api_data-> query-> Seiten-> Revisionen [0] -> {'*'}; ' – Chay22

+0

danke das hat geholfen !! – colourtheweb

Antwort

0

Sie können den Eigenschaftsnamen in Klammern verwenden, wie Chay22 vorgeschlagen:

$data->first = 'hello'; 
$data->{'*'} = 'world'; 

var_dump($data); 

// Like this 
echo $data->{'*'}; 
echo PHP_EOL; 

// or like this 
$varname = '*'; 

echo $data->{$varname}; 
echo PHP_EOL;