Jump to content

Simple serialized (?) string not being unserialized


newsomjk

Recommended Posts

So basically, this string is in the database and I can't find what saved it so I'm not sure what method they used to create the string... But I need to break it into an array.

 

I tried originally using $array = unserialize($str), however that printed "not ok."  This method prints "ok" however, nothing shows up afterwards.

$str = '{"media_id":"235","stream":"0","maxspeed":"3000","maxloads":"0","mloadperInterval":"0","mloadInterval":"0","maxtime":"0","publish_up":"0","publish_down":"0"}';
echo $str;
$array = json_decode($str);

if ($array !== false) {
    echo "ok";
} else {
    echo "not ok";
}

echo '<br/><br/>'.print_r($array,true);

What am I doing wrong? 

Dunno.  If I run your code I get:

{"media_id":"235","stream":"0","maxspeed":"3000","maxloads":"0","mloadperInterval":"0","mloadInterval":"0","maxtime":"0","publish_up":"0","publish_down":"0"}ok


stdClass Object
(
    [media_id] => 235
    [stream] => 0
    [maxspeed] => 3000
    [maxloads] => 0
    [mloadperInterval] => 0
    [mloadInterval] => 0
    [maxtime] => 0
    [publish_up] => 0
    [publish_down] => 0
)

your code works for me. best guess that code is inside of some other output that is hiding it in the 'view source' in your browser.

 

btw - if you truly want an array as a result, use a true value as the second parameter in $array = json_decode($str,true);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.