Php 非法字符串偏移量';属性';,如何传递json编码的值

Php 非法字符串偏移量';属性';,如何传递json编码的值,php,json,mongodb,echo,var-dump,Php,Json,Mongodb,Echo,Var Dump,如何将json_编码结果的字段分配给变量。我有以下资料: $jsonres = json_encode($result); //where result is an array holding fields including name (string), properties (object type or array) echo $jsonres['properties']; // failed with "Illegal string offset 'properties'" var_d

如何将json_编码结果的字段分配给变量。我有以下资料:

$jsonres = json_encode($result); //where result is an array holding fields including name (string), properties (object type or array)
echo $jsonres['properties']; // failed with "Illegal string offset 'properties'"
var_dump ($jsonres->properties); //"Notice: Trying to get property of non-object in..." 
我尝试了以下方法:

$jsonres = json_encode($result); //where result is an array holding fields including name (string), properties (object type or array)
echo $jsonres['properties']; // failed with "Illegal string offset 'properties'"
var_dump ($jsonres->properties); //"Notice: Trying to get property of non-object in..." 
我需要能够在表单中使用“属性”的值


谢谢

只需编码properties属性,而不是整个对象:

$jsonres = json_encode($result['properties']);
echo $jsonres;

在您的示例中,$jsonres是一个对象。而
$jsonres['properties']
访问数组的元素。你必须使用对象符号(o->prop)。@最后面的,对不起,我没有(o->prop)。似乎类似于我在var_dump($jsonres->properties)上的设置;对吗?你使用的
响应
类的定义在哪里?@Kingsley你很难理解。所以我想您必须:1)将$result解码为php数组(或对象);2) 取回所需财产;3) 将其编码为JSON。我无法提出解决方案,因为我仍然不理解这个问题。我要求提供细节,但OP没有提供。