Json_decode cannot convert JSON to an array after PHP curl

Source: Internet
Author: User
Tags uuid

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 "}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.