如何将Json解码为Array

I have an array like this:

$templateStyleArr = array(
                      0 => array(
                            'text' => 'General Text',
                            'default_value' => '#444',
                            'scopval' => 'general',
                            ),
                      1 => array(
                            'text' => 'Accent Color',
                            'default_value' => '#c91a1a',
                            'scopval' => 'Accent',
                            ),      
                      2 => array(
                            'text' => 'Button Hover',
                            'default_value' => '#2ec72e',
                            'scopval' => 'dark_btn_hover',
                            ),      
                      3 => array(
                            'text' => 'Button Text',
                            'default_value' => '#3300f5',
                            'scopval' => 'btn_txt',
                            ),  
                        )

I want to save this array to data base in Json format using PHP.I am using json_encode function. Json saved perfectly.Problem is When I try to decode the saved json(using json_decode),I am not getting the above array back.

Referring to the manual, you may need to set the assoc parameter to TRUE so that the returned object will be converted into an associative array.

$array = json_decode($json_string_from_db, TRUE);

If you want to store just the array as string in the database you can try serialize(), with unserialize you'll get the exactly same array as return value

$templateStyleArr = array(
    0 => array(
        'text' => 'General Text',
        'default_value' => '#444',
        'scopval' => 'general',
    ),
    1 => array(
        'text' => 'Accent Color',
        'default_value' => '#c91a1a',
        'scopval' => 'Accent',
    ),
    2 => array(
        'text' => 'Button Hover',
        'default_value' => '#2ec72e',
        'scopval' => 'dark_btn_hover',
    ),
    3 => array(
        'text' => 'Button Text',
        'default_value' => '#3300f5',
        'scopval' => 'btn_txt',
    ),
);

$string = serialize( $templateStyleArr );
var_dump( unserialize( $string ) );

If the array indexes are really just numbers you can use this:

$string = json_encode( $templateStyleArr );
$arrayFromJson = json_decode( $string );

foreach( $arrayFromJson as $index => $jsonObject ) {
    // cast object to array
    $arrayFromJson[$index] = (array) $jsonObject;
}

var_dump( $arrayFromJson );

basicly your json encode will convert array to object when you decode it, so you need create function for generate object to array, you should try this function where will convert correct

function to_array( $object ){
    if( !is_object( $object ) && !is_array( $object ) ){
        return $object;
    }
    if( is_object( $object ) ){
        $object = get_object_vars( $object );
    }
    return array_map( 'to_array', $object );
}

$array = to_array( json_decode($fromdb) );

print_r( $array );

it's work okay for me so let's try :)