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

Était-ce utile?

La solution

Simply encode the properties property, not the entire object:

$jsonres = json_encode($result['properties']);
echo $jsonres;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top