It's been a long time. Json_decode cannot convert JSON to an array after PHP Curl:
The data returned by Curl is in BOM format and needs to be converted;
Some return data directly:
Print_r (Json_decode ($data, true));
can be converted.
$url = "http://localhost/web_services.php";
$post _data = Array ("username" => "Bob", "Key" => "12345");
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_post, 1);//POST's variable curl_setopt ($ch, Curlopt_postfields, $post _data); curl_setopt ($ch, Curlopt_returntransfer, true); Get Data back to curl_setopt ($ch, Curlopt_binarytransfer, true);
The fetch data is returned $output = curl_exec ($ch) when the Curlopt_returntransfer is enabled;
Curl_close ($ch);//print obtained data print_r ($output); Get the data: {"Code_img_url": "https:\/\/pay.swiftpass.cn\/pay\/qrcode?uuid=https%3a%2f%2fqr.alipay.com% 2fbax00722bbvbiqp1yp3960a6 "," Code_url ":" Https:\/\/qr.alipay.com\/bax00722bbvbiqp1yp3960a6 "} Conversion: if (Preg_match ('/
^\xef\xbb\xbf/', $output)) {$output = substr ($output, 3);
$info = Json_decode (Trim ($output), true);
Print_r ($info); Array (2) {["Code_img_url"] => string Https://pay.swiftpass.cn/pay/qrcode?uuiD=https%3a%2f%2fqr.alipay.com%2fbax00722bbvbiqp1yp3960a6 "[" Code_url "] => string (+) https://qr.alipay.com/ Bax00722bbvbiqp1yp3960a6 "}