php - Sending " (quote marks) sign over cURL with JSON -


i'm sending array data on curl server (with php). code before sending prepare data:

$array['fielda'] = urlencode('something "special" here'); $array['fieldb'] = urlencode('text & number\'s content'); $data = json_encode($array); // {"fielda":"something+%22special%22+here","fieldb":"text+%26+number%27s+content"} 

and sending curl

curl_setopt($ch, curlopt_httpheader, array('content-type: application/x-www-form-urlencoded')); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, "params=".$data); 

code on other side

$data = json_decode($_post, true); $data['fielda'] = urldecode($data['fielda']); $data['fieldb'] = urldecode($data['fieldb']); 

var_dump of $_post different:

"{"fielda":"something "special" here","fieldb":"text & number's content"}" 

and because there there " (quote marks) not right json structure anymore.

how can fix it? thanks!

the order of operations wrong. should use urlencode() last operation, right before send curl json_encode() add characters not valid in url:

$array['fielda'] = 'something "special" here'; $array['fieldb'] = 'text & number\'s content'; $data = urlencode(json_encode($array)); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -