我想测试一个模块,我需要重新创建一个JSON如下:如何获取特定格式的JSON响应?
$billing_info['billing']->customer_id
$billing_info['billing']['source']->exp_year
我试过如下重建它:
$arr = json_encode(['id'=>'card_17LHmCI49Oxjrr81SringkGq', 'exp_year'=>2018, 'exp_month' => 07, 'funding' => 'credit', 'brand' => 'Visa', 'last4' => '4242']);
$customer = json_encode(['customer_id' => 'cus_7aSheljul3mkAB', 'source' =>json_decode($arr)]);
但我不能打电话dd($billing_info['billing']->customer_id);
所需JSON响应是象如下:
[
"billing" => [
{"customer_id": 12 }
"source" => {
"exp_year": 2018
"exp_month": 7
"funding": "credit"
"brand": "Visa"
"last4": "4242"
}
]
]
标记您正在使用的语言。 –
这两个代码块与每个代码块都没有关系(变量名称,数组中的键)。除了json_encode没有必要,因为输入一个字符串 – Gavriel
您正尝试使用'billing_info ['billing']'作为对象(' - > customer_id')和数组('['source']')在同一个时间。它可能在php对象中(magic'offsetGet')。但是我担心,你无法在json中重新创建这样的行为。 –