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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里