1

I am trying to parse a twitter user stats (with php) -- I am pretty unfamiliar with parsing json so this is giving me a bit of a headache (I'm missing something silly here I know). I've looked at a bunch of answers/posts from others but can't quite peg it. Any help is appreciated.

Essentially what i want to get is the [url] and the [text] but I keep getting errors in php.

[0] => stdClass Object
    (
        [in_reply_to_user_id] => 
        [in_reply_to_status_id_str] => 
        [retweet_count] => 0
        [id_str] => 180735710897250304
        [in_reply_to_user_id_str] => 
        [geo] => 
        [favorited] => 
        [user] => stdClass Object
            (
                [id_str] => 46023
                [id] => 460
            )

        [in_reply_to_status_id] => 
        [in_reply_to_screen_name] => 
        [truncated] => 
        [contributors] => 
        [source] => Facebook
        [entities] => stdClass Object
            (
                [hashtags] => Array
                    (
                    )

                [urls] => Array
                    (
                        [0] => stdClass Object
                            (
                                [expanded_url] => http://www.buzzfeed.co
                                [url] => http://t.c
                                [indices] => Array
                                    (
                                        [0] => 0
                                        [1] => 20
                                    )

                                [display_url] => buzzfeed.com/c
                            )

                        [1] => stdClass Object
                            (
                                [expanded_url] => http://fb
                                [url] => http://t.
                                [indices] => Array
                                    (
                                        [0] => 21
                                        [1] => 41
                                    )

                                [display_url] => fb.m
                            )

                    )

                [user_mentions] => Array
                    (
                    )

            )

        [coordinates] => 
        [retweeted] => 
        [id] => 180735
        [created_at] => Fri Mar 16 19:22:06 +0000 2012
        [possibly_sensitive] => 
        [place] => 
        [text] => http://t.co
1
  • Could you please post the code you're using to get this output? Commented Mar 16, 2012 at 20:52

2 Answers 2

1

The json_decode function takes an optional 2nd parameter to return an associative array instead of an object.

Try: json_decode($your_json_var, false)

Then, you can just retrieve the values normally as you would with any array.

Sign up to request clarification or add additional context in comments.

1 Comment

Yup knew this but was trying to get around it for one reason or another.
0

You can also get the values as below for example:

 echo $tweets[0]->id_str;

This will display the id_str value from your json data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.