亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

php語言

php獲取json數(shù)據(jù)所有的節(jié)點路徑

時間:2024-11-07 11:51:37 php語言 我要投稿
  • 相關(guān)推薦

php獲取json數(shù)據(jù)所有的節(jié)點路徑

  文章主要介紹了php獲取json數(shù)據(jù)所有的節(jié)點路徑的方法和實例,有需要的小伙伴可以參考下。

  之前我們講解過使用javascript獲取json數(shù)據(jù)節(jié)點路徑的問題,今天我們更進(jìn)一步,講解下php獲取json數(shù)據(jù)所有的節(jié)點路徑

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  15

  16

  17

  18

  19

  20

  21

  22

  23

  24

  25

  26

  27

  28

  29

  30

  31

  32

  33

  34

  35

  36

  37

  38

  39

  40

  41

  42

  43

  44

  45

  <?php

  function iterTree($data) {

  $retData = array();

  $data = json_decode($data, true);

  if (!is_array($data) && empty($data)) {

  echo 'error !' ."n";

  } else {

  $queue = array();

  foreach ($data as $field => $value) {

  $queue[] = $field;

  }

  $head = 0;

  $tail = count($queue);

  while ($head < $tail) {

  $field = $queue[$head++];

  $path = explode("/", $field);

  $tmpData = &$data;

  foreach ($path as $key => $ph) {

  $tmpData = &$tmpData[$ph];

  }

  if (is_array($tmpData) && !empty($tmpData)) {

  $newField = $field;

  foreach ($tmpData as $curField => $curValue) {

  $newField = $field . '/' . $curField;

  $queue[$tail++] = $newField;

  }

  } else {

  $retData[] = $field;

  }

  }

  }

  return $retData;

  }

  //測試數(shù)據(jù)

  $data = file_get_contents("http://restapi.ele.me/v1/restaurants?extras%5B%5D=food_activity&extras%5B%5D=restaurant_activity&extras%5B%5D=certification&fields%5B%5D=id&fields%5B%5D=name&fiel

  ds%5B%5D=phone&fields%5B%5D=promotion_info&fields%5B%5D=name_for_url&fields%5B%5D=flavors&fields%5B%5D=is_time_ensure&fields%5B%5D=is_premium&fields%5B%5D=image_path&fields%5B%5D=rating&fie

  lds%5B%5D=is_free_delivery&fields%5B%5D=minimum_order_amount&fields%5B%5D=order_lead_time&fields%5B%5D=is_support_invoice&fields%5B%5D=is_new&fields%5B%5D=is_third_party_delivery&fields%5B%

  5D=is_in_book_time&fields%5B%5D=rating_count&fields%5B%5D=address&fields%5B%5D=month_sales&fields%5B%5D=delivery_fee&fields%5B%5D=minimum_free_delivery_amount&fields%5B%5D=minimum_order_des

  cription&fields%5B%5D=minimum_invoice_amount&fields%5B%5D=opening_hours&fields%5B%5D=is_online_payment&fields%5B%5D=status&fields%5B%5D=supports&fields%5B%5D=in_delivery_area&geohash=wx4g07

  j0w1v7&is_premium=0&limit=1000&offset=24&type=geohash");

  $ret = iterTree($data);

  print_r($ret);

【php獲取json數(shù)據(jù)所有的節(jié)點路徑】相關(guān)文章:

PHP中Json應(yīng)用09-05

如何實現(xiàn)PHP獲取表單數(shù)據(jù)與HTML嵌入PHP腳本09-23

php獲取新浪微博數(shù)據(jù)API的實例代碼08-06

PHP如何遞歸實現(xiàn)json類06-27

PHP獲取星期的方法07-06

PHP如何獲取表單07-27

適用于多條件篩選列表的PHP獲取當(dāng)前URL路徑09-07

在PHP語言中使用JSON09-14

php創(chuàng)建cookie獲取方法10-28

PHP如何獲取系統(tǒng)信息11-04