无法将Joomla fieldparams作为数组或对象

I would get Joomla custom fields values from a PHP script. I include all necessary files and I can read checkbox values from "fields" table, the "fieldparams" column. If I execute this code

$query = "select #__fields.fieldparams from   #__fields where  #__fields.id = 19";
$db->setQuery($query);
$result = $db->loadRowList();
foreach ($result as $value) {
echo gettype($value); // 01
echo $value[0]; // 02
$var = json_encode($value[0]);
echo gettype($var); // 03
}

the type of $value is "Array" (step 01), so if I access to $value[0] the result (step 02) is the global list (so I suppose this is an Array with 1 element)

{
"options":{
"options0":{"name":"type1","value":"1"},
"options1":{"name":"type2","value":"2"},
"options2":{"name":"type3","value":"3"},
"options3":{"name":"type4","value":"4"},
"options4":{"name":"type5","value":"5"}
}
}

but when I try to use json_encode the result (step 03) is a string. In this way I can't access to keys and relative values.

What's wrong?

There are 2 issues here. 1. You're using ->loadRowList() which is a method designed to return an array of rows (i.e. multiple rows), not one as is implied by your where clause, and 2. Rather than using PHP's native functions, try using Joomla's JRegistry class instead.

To address these points:

1 Since you're only expecting 1 row to be returned (field with ID 19), replace your line:

$result = $db->loadRowList();

with

$result = $db->loadResult();

$result will contain the fieldparams column only.

2 Create an instance of the JRegistry class so we can access the key => value pairs:

// new registry
$registry = new JRegistry();
$registry->loadString($result); // load the string from the db

// if you need an array, use jregistry's toArray method
$arrayData = $registry->toArray();

Hope it helps,

Gez