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 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案