1
I need to generate a JSON in the following format below:
{
'plan_id' => 2,
'customer_id' => 16,
'payment_method_code' => 'credit_card',
'product_items' => [
[
'product_id' => 3
]
[
'product_id' => 4
]
]
}
But I can’t with my PHP code:
$dados_assinatura = array(
'plan_id' => $plano,
'customer_id' => $cliente_id,
'payment_method_code' => 'credit_card',
'product_items' => array()
);
foreach ($array_opcionais as $produto) {
$dados_assinatura['product_items'][][] = array (
'product_id' => $produto
);
}
The generated JSON is:
{
"plan_id":"60412",
"customer_id":6527983,
"payment_method_code":"credit_card",
"product_items":[
[
{
"product_id":"221663"
}
],
[
{
"product_id":"221666"
}
],
[
{
"product_id":"221667"
}
],
[
{
"product_id":"221668"
}
]
]
}
Yes, because there is no JSON syntax
['product_id' => 4]. If it is associative data, it will be an object, with{}. Brackets are for lists only.– Woss