开发者

Decoding json in twitter using Eliiot Twitter For Codeigniter

Currently Im trying to use elliots twitter library for CI at http://www.haughin.com/code/twitter/ after installation, it went well. the source code worked well..

Then I try to add code at index() function which is like this :

function index()
        {
            echo 'hi there';

            $user = $this->tweet->call('get', 'acco开发者_StackOverflow中文版unt/verify_credentials');

            $dec = json_decode($user);
        }

I tried to decode json by using json_decode() function but it return error

json_decode() expects parameter 1 to be string, object given

This is my first time working with json.. Is there something I missed out ? Thank you..


You should juggling that object into string type...

 $user = (string) $this->tweet->call('get', 'account/verify_credentials');
 $dec = json_decode($user);


It doesn`t need any variable convertion. just access object directly like $dec->username

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜