PHP: pulling all values from a multidimensional array

Status
Not open for further replies.

naevity

Ars Tribunus Militum
2,758
I come before you asking for assistance. :) I have been working on this all afternoon and I am stuck. I am trying to work with soem JSON data that I do not have control over. The full decoded json is below. I'm trying to get the value of a sub array, but with them being defined as stdClass Object I'm lost.

It should be a simple foreach, but I just can't figure out the proper way to do it. any one have any idea? I want to get the value section of these three objects:

[0] => stdClass Object
(
[Name] => 1
[Value] => |id1|MA|101|
)
[1] => stdClass Object
(
[Name] => 2
[Value] => |id2|CA|600|
)
[2] => stdClass Object
(
[Name] => 3
[Value] => |id3|FL|467|
)




Code:
stdClass Object
(
    [Properties] => Array
        (
        )

    [Name] => 
    [Children] => Array
        (
            [0] => stdClass Object
                (
                    [Properties] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [Name] => rowCount
                                    [Value] => 3
                                )
                            [1] => stdClass Object
                                (
                                    [Name] => columnCount
                                    [Value] => 3
                                )
                            [2] => stdClass Object
                                (
                                    [Name] => 0-1-name
                                    [Value] => playerID
                                )
                            [3] => stdClass Object
                                (
                                    [Name] => 0-1-type
                                    [Value] => 1
                                )
                            [4] => stdClass Object
                                (
                                    [Name] => 0-2-name
                                    [Value] => playerName
                                )
                            [5] => stdClass Object
                                (
                                    [Name] => 0-2-type
                                    [Value] => 1
                                )
                            [6] => stdClass Object
                                (
                                    [Name] => 0-3-name
                                    [Value] => playerstats
                                )
                            [7] => stdClass Object
                                (
                                    [Name] => 0-3-type
                                    [Value] => 2
                                )
                        )
                    [Name] => id911451_headers
                    [Children] => Array
                        (
                        )
                )
            [1] => stdClass Object
                (
                    [Properties] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [Name] => 1
                                    [Value] => |id1|MA|101|
                                )
                            [1] => stdClass Object
                                (
                                    [Name] => 2
                                    [Value] => |id2|CA|600|
                                )
                            [2] => stdClass Object
                                (
                                    [Name] => 3
                                    [Value] => |id3|FL|467|
                                )
                        )
                    [Name] => id911451
                    [Children] => Array
                        (
                        )
                )
        )
)
 

naevity

Ars Tribunus Militum
2,758
[url=http:/civis/viewtopic.php?p=26099213#p26099213:1dnfzizd said:
SituationSoap[/url]":1dnfzizd]What JSON Parsing library are you using that's moving things out to StdClass Objects?

good question, forgot to mention that, this the whole process. I am trying to upload data from a mobile app. the SDK converts it to json and sends it to my server. This is what I'm doing:

Code:
$jsondata = $_POST["params"];
$array = json_decode($jsondata);
file_put_contents($jsondata);


The incoming json looks like this. after running it through the json_decode I output it to a file to check the format, that is what I posted above.

Code:
{"Properties":[],"Name":"","Children":[{"Properties":[{"Name":"rowCount","Value":3},{"Name":"columnCount","Value":3},{"Name":"0-1-name","Value":"playerID"},{"Name":"0-1-type","Value":1},{"Name":"0-2-name","Value":"playerName"},{"Name":"0-2-type","Value":1},{"Name":"0-3-name","Value":"playerstats"},{"Name":"0-3-type","Value":2}],"Name":"id911451_headers","Children":[]},{"Properties":[{"Name":"1","Value":"player1|id1|MA|101|"},{"Name":"2","Value":"player2|id2|CA|600|"},{"Name":"3","Value":"player3|id3|FL|467|"}],"Name":"id911451","Children":[]}]}
 

naevity

Ars Tribunus Militum
2,758
and that is probably the problem. I forgot to pass in true to get an array out of the json_decode. so this is the real output:

Code:
Array
(
    [Properties] => Array
        (
        )

    [Name] => 
    [Children] => Array
        (
            [0] => Array
                (
                    [Properties] => Array
                        (
                            [0] => Array
                                (
                                    [Name] => rowCount
                                    [Value] => 3
                                )

                            [1] => Array
                                (
                                    [Name] => columnCount
                                    [Value] => 3
                                )

                            [2] => Array
                                (
                                    [Name] => 0-1-name
                                    [Value] => playerID
                                )

                            [3] => Array
                                (
                                    [Name] => 0-1-type
                                    [Value] => 1
                                )

                            [4] => Array
                                (
                                    [Name] => 0-2-name
                                    [Value] => playerName
                                )

                            [5] => Array
                                (
                                    [Name] => 0-2-type
                                    [Value] => 1
                                )

                            [6] => Array
                                (
                                    [Name] => 0-3-name
                                    [Value] => playerstats
                                )

                            [7] => Array
                                (
                                    [Name] => 0-3-type
                                    [Value] => 2
                                )

                        )

                    [Name] => id911451_headers
                    [Children] => Array
                        (
                        )

                )

            [1] => Array
                (
                    [Properties] => Array
                        (
                            [0] => Array
                                (
                                    [Name] => 1
                                    [Value] => player1|id1|MA|101|
                                )

                            [1] => Array
                                (
                                    [Name] => 2
                                    [Value] => player2|id2|CA|600|
                                )

                            [2] => Array
                                (
                                    [Name] => 3
                                    [Value] => player3|id3|FL|467|
                                )

                        )

                    [Name] => id911451
                    [Children] => Array
                        (
                        )

                )

        )

)
 

naevity

Ars Tribunus Militum
2,758
[url=http:/civis/viewtopic.php?p=26099511#p26099511:1gc7clz9 said:
SituationSoap[/url]":1gc7clz9]I'm having trouble understanding what your problem is at this point. It should be a simple foreach, no?

yea, originally it was because the stdClass object was throwing me off. now that I have an array I just need to figure out the foreach call. I haven't coded in PHP in a few years so it's been a little bit of pain. thanks!
 
Status
Not open for further replies.