doy51723 2012-01-19 13:26
浏览 46

如何使用json_decode提取内部信息

I am new to php. I need some quick help with json_decode/php. I need to get values of g91 in an array, how can I do this? I suppose there is some recursion value that we can pass to json_decode...

{
    "e": "none",
    "f": "test",
    "g": [
        {
            "g1": "text2",
            "g9": {
                "text3": {
                    "g91": 0,
                    "g92": [
                        "text5"
                    ]
                }
            }
        },
        {
            "g1": "text1",          
            "g9": {
                "text4": {
                    "g91": 0,
                    "g92": [
                        "text6",
                        "text7"
                    ]
                }
            }
        }
    ]
}

Please note that text3 is not fixed..in next record, I have text4..

Thanks!

  • 写回答

4条回答 默认 最新

  • dtbam62840 2012-01-19 13:31
    关注

    After decode you will get an PHP array, just go to desired index:

    $myJson['g'][0]['g9']['text3']['g91'];
    

    But you can make some recursive loop to find all the results you search in that array.

    Take a look in array docs from PHP: http://br2.php.net/manual/en/book.array.php

    评论

报告相同问题?