简体   繁体   English

PHP解码JSON变量

[英]PHP Decode JSON variables

I have the following json file below that outputs the following information: 我在下面的以下json文件中输出以下信息:

stdClass Object
(
[status] => OK
[droplet] => stdClass Object
    (
        [id] => 567894
        [name] => Luna
        [created_at] => 2013-10-10T18:13:08Z

    )

)

I'm trying to get the [name] and save it to a variable called $serverName. 我正在尝试获取[名称]并将其保存到名为$ serverName的变量中。 I've tried using the code below but have no luck :/ 我尝试使用下面的代码,但没有运气:/

<?php
    $request = 'Link to JSON FILE';
    $response  = file_get_contents($request);
    $jsonobj  = json_decode($response);

    $serverName = $jsonobj->name;

I've tried looking online but I'm having troubles getting this to work :/ 我曾尝试过在网上寻找内容,但无法正常工作:/

Thanks a ton <3 吨<3

Got it to work. 得到它的工作。 Just need to do; 只需要做;

$jsonobj->droplet->name; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM