문제

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

도움이 되었습니까?

해결책

Simply encode the properties property, not the entire object:

$jsonres = json_encode($result['properties']);
echo $jsonres;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top