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