duai0935 2013-05-27 10:08
浏览 307
已采纳

从URL中提取JSON格式的数据

Hi i have been trying to pull data in JSON format. Here is my code

$resourse_url  = 'http://www.livepicly.com/app/api.php?method=list_vendor_name';
$json_data = file_get_contents($resourse_url);
$json_output = json_decode($json_data, TRUE);

$vendor = $json_output['vendor_name'][1];

echo "<pre>";
print_r($vendor);
exit(1);

However when i run the code it does not return anything. When i try to access the source URL via firefox, it asks me where to save the JSON data as *.php, however when i access the source URL from Chrome it displays the JSON data as normal.

What do i have to do here? Can anyone point me to a solution? Thx

  • 写回答

1条回答 默认 最新

  • doujiao3998 2013-05-27 10:18
    关注

    running the returned json on http://jsonformatter.curiousconcept.com/

    {
       "result":[
          {
             "vendor_id":"726",
             "vendor_name":"Scusa"
          },
          {
             "vendor_id":"519",
             "vendor_name":"Emilie French Restaurant and Bar"
          },
          {
             "vendor_id":"482",
             "vendor_name":"Cassis French Fine Dining"
          },
          {
             "vendor_id":"435",
             "vendor_name":"Asuka Japanase Dining"
          },
          {
             "vendor_id":"12050",
             "vendor_name":"Taipan"
          },
          {
             "vendor_id":"12061",
             "vendor_name":"Social House"
          },
          {
             "vendor_id":"12103",
             "vendor_name":"Harum Manis Indonesian Restaurant"
          },
          {
             "vendor_id":"12193",
             "vendor_name":"Nanny\'s Pavillion (Central Park)"
          },
          {
             "vendor_id":"12272",
             "vendor_name":"Bistro Baron"
          },
          {
             "vendor_id":"20704",
             "vendor_name":"Kitchenette (Central Park)"
          },
          {
             "vendor_id":"21217",
             "vendor_name":"Kitchenette (Plaza Indonesia)"
          },
          {
             "vendor_id":"29859",
             "vendor_name":"Momento Restaurant And Bar"
          },
          {
             "vendor_id":"31055",
             "vendor_name":"Tortuga Kitchen And Bar"
          },
          {
             "vendor_id":"31056",
             "vendor_name":"Tuck And Chug"
          },
          {
             "vendor_id":"31060",
             "vendor_name":"AUROZ Gourmet Grill"
          }
       ]
    }
    

    it found invalid characters on this line

    "vendor_name":"Nanny\'s Pavillion (Central Park)"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题