Avatar

[PHP] Jemand da, der sich mit JSON auskennt?

You may notice, that many sections are currently only available in german. We are working hard to provide a full translation of our website, but this might take some time. Thank you for understanding.
  • Hallo zusammen,


    kann mir jemand vllt bei einem Problem helfen, was das Auslesen einer JSON Response betrifft?


    Es geht um folgende Response:

    134819 ist Dynamisch, also ändert sich immer.


    wie kann ich die Blöcke "Downloadserver 1 - 6 ausgeben", sprich: Den Name "Downloadserver X" und jeweils "//downloadfile/file.zip".


    Wäre über einen Codeschnipsel sehr dankbar.


    LG

  • Ab PHP 5.2:

    PHP
    <?php
    $json = '{"134819":{"0":"DOWNLOAD: CCLEANER","1":"1","3":"134819","r":{"t":[13,11],"b":[14,11]},"2":"DOWNLOAD: CCLEANER","links":{"Downloadserver 1":[["1","mediabox","icon.ico","//downloadfile/file.zip","81","stream","0"]],"Downloadserver 2":[["1","redirect","none","//downloadfile/file.zip","123","download","0"]],"Downloadserver 3":[["1","redirect","so.ico","//downloadfile/file.zip","67","download","1"]],"Downloadserver 4":[["1","redirect","none","//downloadfile/file.zip","506","download","5"]],"Downloadserver 5":[["1","redirect","none","//downloadfile/file.zip","129","stream","8"]],"Downloadserver 6":[["1","redirect","none","//downloadfile/file.zip","502","download","18"]]}}}';
    $arr = json_decode($json);
    foreach(reset($arr)->links as $server => $link) {
    echo "{$server}: {$link[0][3]}<br />\n";
    }


    =>


    Code
    Downloadserver 1: //downloadfile/file.zip<br />
    Downloadserver 2: //downloadfile/file.zip<br />
    Downloadserver 3: //downloadfile/file.zip<br />
    Downloadserver 4: //downloadfile/file.zip<br />
    Downloadserver 5: //downloadfile/file.zip<br />
    Downloadserver 6: //downloadfile/file.zip<br />
  • Ich danke dir für deine Hilfe.

    Dieses reset() für die arrays, war mir bislang auch nicht so geläufig.


    Vielen Dank!


    LG

  • $data = array_pop($arr)

    $data = array_shift($arr)

    array_values($arr); $data = $arr[0];


    Da gibts zig varianten^^

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!