解析使用PHP对于Yelp的API JSON响应 [英] Parsing JSON response using PHP for Yelp API

查看:202
本文介绍了解析使用PHP对于Yelp的API JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法解析由Yelp的API发送的信息。下面是输出: http://www.coroomer.com/apartments/yelp.php

I can't seem to parse information sent by the Yelp API. Here's the output: http://www.coroomer.com/apartments/yelp.php.

下面是我有麻烦code的片段:

Here is the segment of the code I am having trouble with:

// Send Yelp API Call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $signed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
$response = curl_exec($ch);
curl_close($ch);

// Handle Yelp response data
$obj = json_decode($response,true);

// Print it for debugging
//print_r($obj);

echo var_dump($obj);

if (isset($bus)) {
foreach($obj[businesses] as $bus){
    echo $bus[name];
    echo $bus[reviews];
    }
}

问题是,我不能得到一个正确的格式化的输出。格式化为它看起来像Yelp的上审查线程。任何帮助是AP preciated。

The problem is that I can't get a correctly "formatted" output. Formatted as in it looks like the review threads on Yelp. Any help is appreciated.

推荐答案

目前还不清楚究竟你问。但是...

It's not clear what exactly you are asking. However...

1。首先解决您的警告和注意事项。不要试图访问阵列周围没有索引的单或双引号,因为PHP将尝试解决这些常量。这将导致:

1. Fix your warnings and notices first. Do not try to access arrays without single or double quotes around indexes, because PHP will try to resolve them as CONSTANTS. Which will lead to:

一个。运行速度较慢

乙。头痛,如果一个常量与该指数存在

b. Headaches, if a constant exists with that index

更改此code:

foreach($obj[businesses] as $bus){
    echo $bus[name];
    echo $bus[reviews];

foreach($obj['businesses'] as $bus){
    echo $bus['name'];
    echo $bus['reviews'];

2。转储没有随着指数的阵列商家,你有什么想在这里遍历?

2. The dump doesn't have any array with the index businesses, what are you trying to iterate over here?

这篇关于解析使用PHP对于Yelp的API JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆