我试图从JSON获取电子邮件的价值,但我认为我的代码不正确。我正在回应价值,但我没有得到打印的价值,请看下面的内容,让我知道它是否不正确
$body='{object: "customer"
created: 1395881542
id: cus_3jvcniqcnhNWID
livemode: true
description: null
email: "support@support.com"
delinquent: false
metadata:
subscriptions:
object: "list"
count: 1
url: "/v1/customers/cus_3jvcniqcnhNWID/subscriptions"
data:
id: sub_3jvcYUNI2ZeM6W
plan:
interval: "month"
name: "Monthly"
created: 1395872091
amount: 999
currency: "gbp"
id: UK DJs Monthly
object: "plan"
livemode: true
"}';
$event_json = json_decode($body);
$getit = $event_json->email;
答案 0 :(得分:1)
这是无效的JSON! JSON要求引用键和字符串,并用逗号分隔项目。添加所需的引号后,它可以正常工作:
$body='{"object": "customer",
"created": 1395881542,
"id": "cus_3jvfrgrcniqcnhNWID",
"livemode": true,
"description": null,
"email": "support@support.com"}';
$event_json = json_decode($body);
$getit = $event_json->email; // support@support.com