Jump to content

stdClass Object


Go to solution Solved by Ch0cu3r,

Recommended Posts

Hello, I'm not so good in php, but I wan to use an object from a json request. For exemple, I get this result from a request : 

$obj = json_decode($json);
print_r($obj);

the result is : 

stdClass Object ( [status] => ok [count] => 1 [data] => stdClass Object ( [1004089236] => stdClass Object ( [clan] => stdClass Object ( [role_i18n] => Soldier [clan_id] => 1000011572 [role] => private [since] => 1380345600 ) [achievements] => stdClass Object ( [tank_expert_uk] => 0 [medal_dumitru] => 0 [invader] => 9 [medal_lehvaslaiho] => 1 [warrior] => 14 [medal_halonen] => 0 [medal_pascucci] => 2 [medal_orlik] => 0 [medal_brothers_in_arms] => 1 [mousebane] => 0 [tank_expert_france] => 0 [mechanic_engineer_ussr] => 0 [medal_bruno_pietro] => 0 [medal_delanglade] => 0 [lucky_devil] => 1 [defender] => 14 [armor_piercer] => 1 [medal_kay] => 2 [supporter] => 10 [mechanic_engineer] => 0 [steelwall] => 21 [max_sniper_series] => 82 [medal_knispel] => 2 [medal_boelter] => 0 [medal_ekins] => 2 [medal_heroes_of_rassenay] => 0 [medal_tamada_yoshio] => 0 [tank_expert_usa] => 0 [mechanic_engineer_germany] => 0 [max_piercing_series] => 29 [tank_expert] => 0 [iron_man] => 39 [medal_radley_walters] => 1 [kamikaze] => 1 [tank_expert_germany] => 0 [beasthunter] => 1 [sniper] => 57 [medal_tarczay] => 0 [medal_lavrinenko] => 2 [mechanic_engineer_france] => 0 [medal_oskin] => 0 [medal_burda] => 0 [medal_billotte] => 1 [huntsman] => 0 [hand_of_death] => 1 [medal_fadin] => 2 [medal_lafayette_pool] => 0 [max_killing_series] => 6 [tank_expert_china] => 0 [mechanic_engineer_usa] => 0 [medal_kolobanov] => 0 [patton_valley] => 0 [bombardier] => 0 [medal_abrams] => 2 [max_invincible_series] => 7 [medal_poppel] => 2 [medal_crucial_contribution] => 0 [raider] => 0 [max_diehard_series] => 7 [mechanic_engineer_uk] => 0 [invincible] => 1 [lumberjack] => 0 [sturdy] => 18 [title_sniper] => 1 [sinai] => 1 [diehard] => 0 [medal_carius] => 2 [medal_le_clerc] => 2 [tank_expert_ussr] => 0 [evileye] => 1 [mechanic_engineer_china] => 0 [medal_nikolas] => 0 [scout] => 4 ) [statistics] => stdClass Object ( [clan] => stdClass Object ( [spotted] => 0 [hits] => 0 [battle_avg_xp] => 0 [draws] => 0 [wins] => 0 [losses] => 0 [capture_points] => 0 [battles] => 0 [damage_dealt] => 0 [hits_percents] => 0 [damage_received] => 0 [shots] => 0 [xp] => 0 [frags] => 0 [survived_battles] => 0 [dropped_capture_points] => 0 ) [all] => stdClass Object ( [spotted] => 3887 [hits] => 27203 [battle_avg_xp] => 418 [draws] => 74 [wins] => 2421 [losses] => 2749 [capture_points] => 9618 [battles] => 5244 [damage_dealt] => 2972693 [hits_percents] => 50 [damage_received] => 2940815 [shots] => 54700 [xp] => 2191030 [frags] => 3726 [survived_battles] => 1397 [dropped_capture_points] => 4312 ) [company] => stdClass Object ( [spotted] => 13 [hits] => 52 [battle_avg_xp] => 235 [draws] => 0 [wins] => 8 [losses] => 23 [capture_points] => 79 [battles] => 31 [damage_dealt] => 8427 [hits_percents] => 63 [damage_received] => 19152 [shots] => 82 [xp] => 7300 [frags] => 12 [survived_battles] => 7 [dropped_capture_points] => 1 ) [max_xp] => 1965 ) [account_id] => 1004089236 [created_at] => 1360891496 [updated_at] => 1383038345 [private] => [nickname] => eric_QC ) ) ) 

It's easy to retrieve the status for exemple, the variable is $obj->status, but if I want to retrieve clan_id variable, it's another thing !

 

I tried many thing, searched on internet, but simple exemple doesn't help me, since it's more complicated here ... 

 

Thank you if you can help me.

Link to comment
https://forums.phpfreaks.com/topic/283513-stdclass-object/
Share on other sites

 

When using print_r() put it between <pre>..</pre> tags. It makes it so much more readable

echo '<pre>', print_r($obj, true), '</pre>';

the result is :

stdClass Object
(
    [status] => ok
    [count] => 1
    [data] => stdClass Object
        (
            [1000377128] => stdClass Object
                (
                    [clan] => stdClass Object
                        (
                            [role_i18n] => Soldier
                            [clan_id] => 1000011572
                            [role] => private
                            [since] => 1380571113
                        )

                    [achievements] => stdClass Object
                        (
                            [tank_expert_uk] => 0
                            [medal_dumitru] => 0
                            [invader] => 29
                            [medal_lehvaslaiho] => 0
                            [warrior] => 53
                            [medal_halonen] => 1
                            [medal_pascucci] => 2
                            [medal_orlik] => 0
                            [medal_brothers_in_arms] => 0
                            [mousebane] => 3
                            [tank_expert_france] => 0
                            [mechanic_engineer_ussr] => 0
                            [medal_bruno_pietro] => 0
                            [medal_delanglade] => 0
                            [lucky_devil] => 3
                            [defender] => 21
                            [armor_piercer] => 1
                            [medal_kay] => 2
                            [supporter] => 72
                            [mechanic_engineer] => 0
                            [steelwall] => 168
                            [max_sniper_series] => 116
                            [medal_knispel] => 1
                            [medal_boelter] => 11
                            [medal_ekins] => 1
                            [medal_heroes_of_rassenay] => 0
                            [medal_tamada_yoshio] => 0
                            [tank_expert_usa] => 1
                            [mechanic_engineer_germany] => 0
                            [max_piercing_series] => 33
                            [tank_expert] => 1
                            [iron_man] => 9
                            [medal_radley_walters] => 0
                            [kamikaze] => 7
                            [tank_expert_germany] => 1
                            [beasthunter] => 16
                            [sniper] => 191
                            [medal_tarczay] => 0
                            [medal_lavrinenko] => 2
                            [mechanic_engineer_france] => 0
                            [medal_oskin] => 0
                            [medal_burda] => 0
                            [medal_billotte] => 7
                            [huntsman] => 0
                            [hand_of_death] => 1
                            [medal_fadin] => 6
                            [medal_lafayette_pool] => 0
                            [max_killing_series] => 7
                            [tank_expert_china] => 0
                            [mechanic_engineer_usa] => 0
                            [medal_kolobanov] => 0
                            [patton_valley] => 0
                            [bombardier] => 0
                            [medal_abrams] => 2
                            [max_invincible_series] => 3
                            [medal_poppel] => 1
                            [medal_crucial_contribution] => 0
                            [raider] => 0
                            [max_diehard_series] => 6
                            [mechanic_engineer_uk] => 0
                            [invincible] => 0
                            [lumberjack] => 0
                            [sturdy] => 13
                            [title_sniper] => 1
                            [sinai] => 9
                            [diehard] => 0
                            [medal_carius] => 1
                            [medal_le_clerc] => 2
                            [tank_expert_ussr] => 1
                            [evileye] => 6
                            [mechanic_engineer_china] => 0
                            [medal_nikolas] => 0
                            [scout] => 65
                        )

                    [statistics] => stdClass Object
                        (
                            [clan] => stdClass Object
                                (
                                    [spotted] => 36
                                    [hits] => 150
                                    [battle_avg_xp] => 488
                                    [draws] => 3
                                    [wins] => 21
                                    [losses] => 22
                                    [capture_points] => 46
                                    [battles] => 46
                                    [damage_dealt] => 69828
                                    [hits_percents] => 50
                                    [damage_received] => 46667
                                    [shots] => 300
                                    [xp] => 22433
                                    [frags] => 39
                                    [survived_battles] => 21
                                    [dropped_capture_points] => 1
                                )

                            [all] => stdClass Object
                                (
                                    [spotted] => 22199
                                    [hits] => 83404
                                    [battle_avg_xp] => 520
                                    [draws] => 301
                                    [wins] => 8084
                                    [losses] => 7720
                                    [capture_points] => 29027
                                    [battles] => 16105
                                    [damage_dealt] => 14218971
                                    [hits_percents] => 51
                                    [damage_received] => 12595110
                                    [shots] => 164694
                                    [xp] => 8368804
                                    [frags] => 12810
                                    [survived_battles] => 4032
                                    [dropped_capture_points] => 9925
                                )

                            [company] => stdClass Object
                                (
                                    [spotted] => 177
                                    [hits] => 666
                                    [battle_avg_xp] => 489
                                    [draws] => 7
                                    [wins] => 91
                                    [losses] => 84
                                    [capture_points] => 96
                                    [battles] => 182
                                    [damage_dealt] => 147101
                                    [hits_percents] => 40
                                    [damage_received] => 127809
                                    [shots] => 1685
                                    [xp] => 89011
                                    [frags] => 104
                                    [survived_battles] => 58
                                    [dropped_capture_points] => 142
                                )

                            [max_xp] => 2413
                        )

                    [account_id] => 1000377128
                    [created_at] => 1302651921
                    [updated_at] => 1383323465
                    [private] => 
                    [nickname] => di0nys0s
                )

        )

)
Link to comment
https://forums.phpfreaks.com/topic/283513-stdclass-object/#findComment-1456531
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.