开发者

PHP json decoding

开发者 https://www.devze.com 2023-03-29 21:09 出处:网络
can someone help me decode this json into php? here is the json: { \"queue\": { \"active_lang\": \"en\", \"paused\": false,

can someone help me decode this json into php?

here is the json:

{
    "queue": {
        "active_lang": "en",
        "paused": false,
        "session": "9bc093acde2a3833569ace5f71ee134e",
        "restart_req": false,
        "power_options": true,
        "slots": [
            {
                "status": "Downloading",
                "开发者_开发知识库index": 0,
                "eta": "22:23 Sun 21 Aug",
                "missing": 0,
                "avg_age": "3h",
                "script": "None",
                "msgid": "",
                "verbosity": "",
                "mb": "534.79",
                "sizeleft": "462 MB",
                "filename": "VA_-_Drum_and_Bass_Summer_Slammers_2011-(VPRLP003S2)-WEB-2011-HB",
                "priority": "Normal",
                "cat": "music",
                "mbleft": "462.17",
                "timeleft": "4:05:09",
                "percentage": "13",
                "nzo_id": "SABnzbd_nzo_mhammg",
                "unpackopts": "3",
                "size": "535 MB"
            }
        ],
        "speed": "32 K",
        "helpuri": "http://wiki.sabnzbd.org/",
        "size": "535 MB",
        "uptime": "2h",
        "refresh_rate": "10",
        "limit": 0,
        "isverbose": false,
        "start": 0,
        "version": "0.6.8",
        "new_rel_url": "",
        "diskspacetotal2": "1843.48",
        "color_scheme": "gold",
        "diskspacetotal1": "1843.48",
        "nt": true,
        "status": "Downloading",
        "last_warning": "",
        "have_warnings": "0",
        "cache_art": "6",
        "sizeleft": "462 MB",
        "finishaction": null,
        "paused_all": false,
        "cache_size": "4 MB",
        "finish": 0,
        "new_release": "",
        "pause_int": "0",
        "mbleft": "462.17",
        "diskspace1": "703.54",
        "scripts": [],
        "categories": [
            "*",
            "movies",
            "music",
            "series",
            "software",
            "tv"
        ],
        "darwin": false,
        "timeleft": "4:05:09",
        "mb": "534.79",
        "noofslots": 1,
        "eta": "22:23 Sun 21 Aug",
        "nzb_quota": "",
        "loadavg": "",
        "cache_max": "8388608",
        "kbpersec": "32.17",
        "speedlimit": "",
        "webdir": "C:\\Program Files (x86)\\SABnzbd\\interfaces\\Plush\\templates",
        "queue_details": "0",
        "diskspace2": "703.54"
    }
}

I have this code so far:

$APIArray = json_decode($urlContents, true);
    $APIqueue = ($APIArray['queue']);
    $APIkbpersec = ($APIArray['kbpersec']);
//        print_r($APIkbpersec);
    echo $APIkbpersec;

but I cant seem to print out the "kbpersec" or any other value from the json. I have worked with json before, but I cant seem to fiqure this out, if anyone could help, that would be great.


Your kbpersec is in the array under your $APIqueue variable, not the $APIArray one.

Change your code to this:

$APIArray = json_decode($urlContents, true);

$APIqueue = $APIArray['queue'];
$APIkbpersec = $APIqueue['kbpersec'];

echo $APIkbpersec;

or:

$APIArray = json_decode($urlContents, true);

$APIqueue = $APIArray['queue'];
$APIkbpersec = $APIArray['queue']['kbpersec'];

echo $APIkbpersec;
0

精彩评论

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

关注公众号