dongtuoji5396 2014-01-22 19:15
浏览 276

在JSON字符串中获取嵌套数组的最简单方法

$json_string = 'http://pubapi.cryptsy.com/api.php?method=marketdatav2';

$jsondata = file_get_contents($json_string);

I am new in php. Maybe its stupid question. But what is the easiest way to get lastestprice of all markets?

  • 写回答

2条回答 默认 最新

  • doufeixuan8882 2014-01-22 19:18
    关注

    Use json_decode function to convert json string to array & traverse the array accordingly.

     $jsondata = file_get_contents($json_string);
     $array = json_decode($jsondata,true);
     foreach($array['return']['markets'] as $lprice) {
      $latest_price[$lprice['label']] = $lprice['lasttradeprice'];
    }
     echo "<pre>";
     print_r($latest_price);
     echo "<pre>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页