php - How to pass string with serialized JSON instead of JSON object in curl parameters
I am using vdociepher, So I need to pass few parameters to vdociepher url but it is recommended to pass " string with serialized JSON instead of JSON object " So I am passing this as per requirement ,but php showing code error like wrong format or improper way of writing.
CURLOPT_URL => "https://dev.vdocipher.com/api/videos/1234567890/otp",
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'licenseRules': json_encode({
'canPersist' => true,
'rentalDuration' => 15 * 24 * 3600
})
]),
I above url I am getting php error in below lines:
CURLOPT_POSTFIELDS => json_encode([
'licenseRules': json_encode({
'canPersist' => true,
'rentalDuration' => 15 * 24 * 3600
})
]),
So what is proper way to write string with serialized json
Answer
Solution:
You have some typo errors. json_encode({
should be json_encode([
, })
should be ])
, and 'licenseRules':
should be 'licenseRules' =>
.
json_encode([
'licenseRules' => json_encode([
'canPersist' => true,
'rentalDuration' => 15 * 24 * 3600
])
]),
But you will have "double encoded" JSON. I think that you should send data like this :
json_encode([
'licenseRules' => [
'canPersist' => true,
'rentalDuration' => 15 * 24 * 3600,
]
]),
Source