Parsing php array in python

I get a PHP array from a web page (as a string). It looks like this:

Array
(
[k1] => Array
    (
        [a] => Array
            (
                [id] => 1
                [age] => 60
            )

        [b] => Array
            (
                [id] => 2
                [age] => 30
            )

    )

[k2] => v2
)

I want to parse it in python. Does anyone have an idea how to do this?

Thanks Rivka

Edit: This is really not json, as some people commented. Thanks for the comments, and I updated the question.

+3
source share
2 answers

This is not JSON, this is how PHP prints arrays. If you want to create JSON from an array, look at json_encode for PHP. Then use the Python JSON library (or here for py3 ) to read it.

+10
source

, print_r . , . :

array('Array'.PHP_EOL."\t(".PHP_EOL."            [0] => test".PHP_EOL."\t)")

array(array('test'));

, (json, serialize ..);

+4

All Articles