Jump to content

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.