yippits api PHP json解码

yippits api PHP json解码,php,object,foreach,json,stdclass,Php,Object,Foreach,Json,Stdclass,我试着从这个回复中循环并抓住细节。不管有多少结果,“交易”部分显然都会重复。我用以下代码解码json响应 $jsonurl = "http://api.yipit.com/v1/deals/?key=&tag=spa"; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json); 但不完全确定如何通过这个与foreach循环?任何帮助开始将非常感谢 "meta": { "

我试着从这个回复中循环并抓住细节。不管有多少结果,“交易”部分显然都会重复。我用以下代码解码json响应

$jsonurl = "http://api.yipit.com/v1/deals/?key=&tag=spa";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
但不完全确定如何通过这个与foreach循环?任何帮助开始将非常感谢

"meta": {
    "code": 200,
    "next": "http://api.yipit.com/v1/deals/?tag=spa&limit=20&key=&offset=20",
    "previous": null
},
"response": {
    "deals": [
        {
            "active": 1,
            "business": {
                "id": 253658,
                "locations": [
                    {
                        "address": "9634 N May Ave",
                        "id": 923137,
                        "lat": 35.5695651,
                        "locality": "Oklahoma City",
                        "lon": -97.5671643,
                        "phone": "405-748-4070",
                        "smart_locality": "Oklahoma City",
                        "state": "OK",
                        "zip_code": "73120"
                    }
                ],
                "name": "Vibrant Life Center",
                "url": "http://vibrantlifeokc.com/"
            },
            "date_added": "2013-05-07 10:43:10",
            "description": "Let the friendly, experienced technicians at this center help you rejuvenate your body with state-of-the-art LipoLaser treatments: \u2022 $77 ($250 value) for one LipoLaser treatment \u2022 $147 ($500 value) for two LipoLaser treatments \u2022 $249 ($1,000 value) for four LipoLaser treatments Why We Love It At this convenient location in The Village, experts use the Stella LipoLaser for this noninvasive procedure for clients 18 and older. You could feel more confident after just one quick 30-minute treatment, so call to schedule an appointment at this office, which is open Tuesday through Saturday. Vibrant Life Center's Website | Facebook",
            "discount": {
                "formatted": "69%",
                "raw": 69
            },
            "division": {
                "active": 1,
                "country": "United States",
                "lat": 35.4673709,
                "lon": -97.516583,
                "name": "Oklahoma City",
                "slug": "oklahoma-city",
                "time_zone_diff": -6,
                "url": "http://yipit.com/oklahoma-city/"
            },
            "end_date": "2013-05-14 09:59:59",
            "id": 19852358,
            "images": {
                "image_big": "http://a.yipitcdn.com/thumbor/zf6rjiAKcs8k9F5RE_rHARXxTfE=/fit-in/372x372/a.yipitcdn.com/deal/feel-fitter-faster-with-lipolaser-treatments-1367922391.jpg",
                "image_small": "http://a.yipitcdn.com/thumbor/b4dO4-uTRFySlYgBVQAxrLYwk4Q=/fit-in/212x212/a.yipitcdn.com/deal/feel-fitter-faster-with-lipolaser-treatments-1367922391.jpg",
                "image_smart": "http://a.yipitcdn.com/thumbor/9p60gjXqwYoPEH637m5IA9_s8c4=/408x357/smart/a.yipitcdn.com/deal/feel-fitter-faster-with-lipolaser-treatments-1367922391.jpg"
            },
            "mobile_url": "http://m.yipit.com/business/vibrant-life-center/?bp_ad=1",
            "price": {
                "formatted": "$77",
                "raw": 77.00
            },
            "source": {
                "name": "LivingSocial",
                "paid": 0,
                "slug": "living-social",
                "url": ""
            },
            "tags": [
                {
                    "name": "Spa",
                    "slug": "spa",
                    "url": ""
                }
            ],
            "title": "Feel Fitter Faster with LipoLaser Treatments",
            "url": "http://yipit.com/aff/eval/deal/?deal=NHFZJTjT&key=fnY4CzVj",
            "value": {
                "formatted": "$250",
                "raw": 250.00
            },
            "yipit_title": "One, Two, or Four LipoLaser Treatments",
            "yipit_url": "http://yipit.com/business/vibrant-life-center/"
        },
json\u decode()
实际上应该向您返回一个对象。为了访问这些属性,您可以
echo$json\u output->meta->code
获取200或
$json\u output->deals[0]->business->id
获取第一笔交易的业务id。注意
{}
[]


我总是建议您使用
var\u dump($json\u output)
,这样您可以在解码后清楚地看到对象的结构。

$json\u output->response->deals
-您收到的所有交易的数组。因此,您需要对其进行迭代以获取其任何信息

e、 g.此代码将回显所有交易描述:

foreach($json_output->response->deals as $deal)
{
    echo $deal->description.'<br />';
}
foreach($json\u输出->响应->交易作为$deal)
{
echo$deal->description.“
”; }
[]
-表示数组。它可以使用循环进行迭代<代码>{}-表示对象(
StdClass
instance)。其属性可通过
->
访问

e、 g.可以像这样检索交易大图(在上一个
foreach
循环的上下文中):


echo$deal->images->images\u big

这非常有效,只需给其他想做同样事情的人一个提示,你的答案是$json_output->response,这应该是响应。(输入错误)我一看到输入错误就成功了。谢谢