Json_decode cannot parse the returned data on the server:
function order_kb(){ $orderaddress[0]['odd']='560860393435'; $this->ajaxReturn($orderaddress,'JSON');}
Client:
$v){ $o.="$k=".urlencode($v)."&";}$data=substr($o,0,-1);$ch = curl_init();curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER,0);curl_setopt($ch, CURLOPT_URL,$url);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);$result = curl_exec($ch);curl_close($curl);print_r('Client:'.$result.'|');print_r('Decode:'.json_decode($result,true).'|');?>
The obtained data [{"odd": "560860393435"}] cannot be parsed.
Reply to discussion (solution)
When you print the string and the array, will not an error be reported ??
Server:
function order_kb(){ $orderaddress[0]['odd']='560860393435'; $this->ajaxReturn($orderaddress,'JSON');}
Client:
$v){ $o.="$k=".urlencode($v)."&";}$data=substr($o,0,-1);$ch = curl_init();curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_HEADER,0);curl_setopt($ch, CURLOPT_URL,$url);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);$result = curl_exec($ch);curl_close($curl);print_r('Client:'.$result.'|');print_r('Decode:'.json_decode($result,true).'|');?>
The obtained data [{"odd": "560860393435"}] cannot be parsed.
No
Print_r ('Client: '. $ result.' | ');
Client: commandid {"odd": "560860393435"}] |
Apparently, a BOM header exists.
So we need
Print_r (json_decode (substr ($ result, 3), true ));
Get
Array
(
[0] => Array
(
[Odd] = & gt; 560860393435
)
)
When you print the string and the array, will not an error be reported ??
No. the same result is returned when the string is removed.
Print_r ('Client: '. $ result.' | ');
Client: commandid {"odd": "560860393435"}] |
Apparently, a BOM header exists.
So we need
Print_r (json_decode (substr ($ result, 3), true ));
Get
Array
(
[0] => Array
(
[Odd] = & gt; 560860393435
)
)
Can I filter through the order_kb () function on the server?
You save the program fileUTF-8 without bomFormat
You save the program fileUTF-8 without bomFormat
Files with notepad looked at, are UTF-8 format
If you are using Notepad to edit the php file, select ANSI when saving the file.
Generally, there is no Chinese character string constant in the program, so if UTF-8 is not selected, it will not affect the whole process.
Someone may tell you to add ob_clean ();
However, this anti-human approach is really undesirable.
If you are using Notepad to edit the php file, select ANSI when saving the file.
Generally, there is no Chinese character string constant in the program, so if UTF-8 is not selected, it will not affect the whole process.
Someone may tell you to add ob_clean ();
However, this anti-human approach is really undesirable.
I used Dreamware to edit the php file. I used notepad to check that the file encoding was UTF-8. Whether php's ajaxReturn is added with the BOM header by default. how can I prevent it from automatically adding
The BOM header is added to your editor (because the default operating system character set is GBK) to indicate the character set of the document
The BOM header is added to your editor (because the default operating system character set is GBK) to indicate the character set of the document
Except for ajaxReturn, is there any other way to return the value back? I think someone else can use json_decode directly to retrieve the interface value. you don't need to process the BOM header.
People's program files do not have BOM headers, so they naturally do not need to be processed!
If you want to use the basic editor to edit php files and stick to UTF-8 encoding, you need to handle the BOM header yourself.
People's program files do not have BOM headers, so they naturally do not need to be processed!
If you want to use the basic editor to edit php files and stick to UTF-8 encoding, you need to handle the BOM header yourself.
Should I use the php editor to create a new file and paste the content to it?
People's program files do not have BOM headers, so they naturally do not need to be processed!
If you want to use the basic editor to edit php files and stick to UTF-8 encoding, you need to handle the BOM header yourself.
This does not work if there is no BOM header.
People's program files do not have BOM headers, so they naturally do not need to be processed!
If you want to use the basic editor to edit php files and stick to UTF-8 encoding, you need to handle the BOM header yourself.
Add ob_end_clean ();