php - JSONPath 查询获取节点名称?

标签 php json jsonpath

考虑以下 JSONPath 片段:

{
   "result":[
      {
         "type":"Residence",
         "street":"Piazza di Spagna",
         "city":"-4:0"
      },
      {
         "type":"Residence",
         "street":"test",
         "city":"-4:1"
      }
   ]
}

是否可以获取所有节点名称的列表?
因此,例如,我想要一个列表,例如:类型、街道、城市。

最佳答案

试试这个

$arr = (json_decode($json)->result[0]);
 $array = get_object_vars($arr);
 $properties = array_keys($array);
 print_r($properties);`

输出将是

Array
(
    [0] => type
    [1] => street
    [2] => city
)

关于php - JSONPath 查询获取节点名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10472610/

相关文章:

php - Instanceof 和命名空间

java - 无法解析 jsonobject--- -"A JSONObject text must begin with ' {' at character 1 of "

kubernetes - kubectl:使用带有 map 的自定义列输出

Jsonpath - 在子级别过滤以获取父属性

java - Json 数组未正确生成

java - 设置嵌套 json 数组的值

php - Elasticsearch PHP 批量索引性能与索引

php - 合并来自 $query->result() 的结果和一个数组 codeigniter

PHP Mailer --- 回复 : --- Return-path --- SetFrom

javascript - 我如何 JSON.parse 来自 URL 的字符串(React Native)