3

看完相关问题后,我不得不在这里提一下我的问题。

我正在运行一个 python 脚本来从 Google place API 获取数据。以某种方式使用 PHP 进行管理,我将对象列表转换为以下输出:

[   {
    'fri_hours': "b'9:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'wed_hours': "b'9:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'sun_hours': "b'Closed'",
    'photo_reference': '',
    'phone_number': b'+1 212-354-1006',
    'state': b'New York',
    'country': b'United States',
    'place_id': 'ChIJ8cFYDKpZwokRpC04mEYm20s',
    'thu_hours': "b'9:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'business_name': b'CarLeo Hair Salon',
    'address': b'22West 38th Street',
    'city': b'New York',
    'mon_hours': "b'9:00 AM \\xe2\\x80\\x93 6:00 PM'",
    'type': 'beauty salon',
    'sat_hours': "b'Closed'",
    'tue_hours': "b'9:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'postal_code': '10018',
    'website': 'http://www.carleohairsalon.com/',
    'rating': 4.6   } ][   {
    'fri_hours': "b'8:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'wed_hours': "b'8:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'sun_hours': "b'Closed'",
    'photo_reference': 'CmRaAAAAe8XIMwcPu3uhohYjJ-dQt69rtZ-x2XJ-I28USF-LphSaVH4Gt-_JUmB06TGnOKKmAqSjnhGuFqUKb7pitV1twViGVE7znVYLSdRYZ72LKjtlXT47YapfEreCmd9lK1R8EhCEJ2Pb2Fpe2sbfbOF3hXgmGhRaJbdZKiF8S0GxdzVj3r7mQphVtw',
    'phone_number': b'+1 212-688-6498',
    'state': b'New York',
    'country': b'United States',
    'place_id': 'ChIJ0SFDYuVYwokRXJvyfmR9kec',
    'thu_hours': "b'8:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'business_name': b'Mizu Salon',
    'address': b'505Park Avenue',
    'city': b'New York',
    'mon_hours': "b'10:00 AM \\xe2\\x80\\x93 6:00 PM'",
    'type': 'beauty salon',
    'sat_hours': "b'9:00 AM \\xe2\\x80\\x93 7:00 PM'",
    'tue_hours': "b'8:00 AM \\xe2\\x80\\x93 7:00 PM'",
    'postal_code': '10022',
    'website': 'http://www.mizuforhair.com/',
    'rating': 4.4   } ]

现在,我只想使用 PHP 将上述输出转换为包含对象子数组的单个数组

我尝试使用 foreach 循环但得到相同的输出。

4

2 回答 2

1

在你的 python 脚本中做类似的事情

import json
#some code here
jsonStr = json.dumps(myListFromGooglePlaces)
#whatever you do to get it to php

然后正如我在上面的评论中提到的

$arr = json_decode($json, true);

我希望这对你有用。

于 2018-05-25T12:03:24.263 回答
0

你可以使用 json_decode 函数

j_obj = '[{ ....}]';

$array = json_decode($j_obj,true);
于 2018-05-25T11:46:31.123 回答