Question

how do I assign a field of a json_encoded result to a variable. I have the following:

$jsonres = json_encode($result); //where result is an array holding fields including name (string), properties (object type or array)

I tried the following:

echo $jsonres['properties']; // failed with "Illegal string offset 'properties'"
var_dump ($jsonres->properties); //"Notice: Trying to get property of non-object in..." 

I need to be able to use the value of 'properties' in my form.

Thanks

Was it helpful?

Solution

Simply encode the properties property, not the entire object:

$jsonres = json_encode($result['properties']);
echo $jsonres;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top