doufu6504 2014-01-28 17:58
浏览 45
已采纳

解码twitter json响应

While working with twitter API, I get response in json format.

I could fetch json value seperately but needs helps in showing response in formatted way.

response looks like:

object(stdClass)#5 (39) { ["id"]=> float(2315798479) ["id_str"]=> string(10) "231579847349" ["name"]=> string(9) "jassy" ["screen_name"]=> string(11) "jasid" ["location"]=> string(0) "" ["description"]=> string(0) "" ["url"]=> NULL ["entities"]=> object(stdClass)#6 (1) { ["description"]=> object(stdClass)#7 (1) { ["urls"]=> array(0) { } } } ["protected"]=> bool(false) ["followers_count"]=> int(1) ["friends_count"]=> int(2) ["listed_count"]=> int(0) ["created_at"]=> string(30) "Tue Jan 28 17:00:38 +0000 2014" ["favourites_count"]=> int(0) ["utc_offset"]=> NULL ["time_zone"]=> NULL ["geo_enabled"]=> bool(false) ["verified"]=> bool(false) ["statuses_count"]=> int(0) ["lang"]=> string(2) "en" ["contributors_enabled"]=> bool(false) ["is_translator"]=> bool(false) ["is_translation_enabled"]=> bool(false) ["profile_background_color"]=> string(6) "C0DEED" ["profile_background_image_url"]=> string(48) "http://abs.twimg.com/images/themes/theme1/bg.png" ["profile_background_image_url_https"]=> string(49) "https://abs.twimg.com/images/themes/theme1/bg.png" ["profile_background_tile"]=> bool(false) ["profile_image_url"]=> string(79) "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png" ["profile_image_url_https"]=> string(80) "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png" ["profile_link_color"]=> string(6) "0084B4" ["profile_sidebar_border_color"]=> string(6) "C0DEED" ["profile_sidebar_fill_color"]=> string(6) "DDEEF6" ["profile_text_color"]=> string(6) "333333" ["profile_use_background_image"]=> bool(true) ["default_profile"]=> bool(true) ["default_profile_image"]=> bool(true) ["following"]=> bool(false) ["follow_request_sent"]=> bool(false) ["notifications"]=> bool(false) }

I can get inditivual value like this:

print $content->{'name'};

php:

$content = $connection->get('account/verify_credentials');
print $content->{'name'}; // 12345
var_dump($content);

I want to see all result in formatted ways. currently response looks like messed up ..

  • 写回答

1条回答 默认 最新

  • doudu9652 2014-01-28 18:04
    关注

    1 - Use HTML pre tags`.

    <pre>
    <?php var_dump($content) ?>
    </pre>
    

    or

    <?php
    echo '<pre>';
    var_dump($content);
    echo '</pre>'
    ?>
    

    2- You don't need this syntax

    $content->{'name'}
    

    Simply use

    $content->name
    

    Also, I recommend you to use the Xdebug extension : it provides nicer formatted output.

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程