Json_decode cannot parse the returned data

Source: Internet
Author: User
Tags urlencode
Server-side:
function order_kb () {    eraddress [0][' odd ']= ' 560860393435 ';    $this->ajaxreturn (eraddress, ' 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);p rint_r (' Client: ' $result. ' | '); Print_r (' Decode: '. Json_decode ($result, True). ' | ');? >

have get to data [{"Odd": "560860393435"}] but can't parse


Reply to discussion (solution)

Do you put strings and arrays together without error when you print??

Server-side:

function order_kb () {    eraddress [0][' odd ']= ' 560860393435 ';    $this->ajaxreturn (eraddress, ' 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);p rint_r (' Client: ' $result. ' | '); Print_r (' Decode: '. Json_decode ($result, True). ' | ');? >

have get to data [{"Odd": "560860393435"}] but can't parse

No

Print_r (' Client: ' $result. ' | '); Get
Client: Nobelium 縖 {"Odd": "560860393435"}]|
Obviously there's a BOM header
So I need this.
Print_r (Json_decode (substr ($result, 3), true));
Have
Array
(
[0] = = Array
(
[Odd] = 560860393435
)

)

Do you put strings and arrays together without error when you print??

No, string removal is the same result

Print_r (' Client: ' $result. ' | '); Get
Client: Nobelium 縖 {"Odd": "560860393435"}]|
Obviously there's a BOM header
So I need this.
Print_r (Json_decode (substr ($result, 3), true));
Have
Array
(
[0] = = Array
(
[Odd] = 560860393435
)

)

Can I filter on the server's order_kb () function?

You save the program file as utf-8 no BOM format

You save the program file as utf-8 no BOM format

The file was read in Notepad, all in UTF-8 format.

If you are using Notepad to edit PHP files, then select ANSI when saving
Usually there is no Chinese string constant in the program, so I do not choose utf-8 and the whole without hindrance

Maybe someone will tell you to add a Ob_clean ();
But this anti-human approach is simply not to be taken.

If you are using Notepad to edit PHP files, then select ANSI when saving
Usually there is no Chinese string constant in the program, so I do not choose utf-8 and the whole without hindrance

Maybe someone will tell you to add a Ob_clean ();
But this anti-human approach is simply not to be taken.

I use Dreamware to edit the php file, with Notepad to see the file encoding is utf-8. PHP Ajaxreturn is the default plus BOM header, how to not let him automatically add

BOM headers are added by your editor (because the default character set for the operating system is GBK) to indicate the character set of the document

BOM headers are added by your editor (because the default character set for the operating system is GBK) to indicate the character set of the document

In addition to Ajaxreturn, is there any other way to return the value back? I see others take the interface value directly Json_decode can, do not have to deal with BOM header

Other people's program files do not have BOM head, nature will not need to deal with!
And you want to use the primary editor to edit PHP files, but also adhere to the Utf-8 code, which naturally requires you to deal with the BOM head

Other people's program files do not have BOM head, nature will not need to deal with!
And you want to use the primary editor to edit PHP files, but also adhere to the Utf-8 code, which naturally requires you to deal with the BOM head

Would you like to use PHP's editor to create a new file to paste the content?

Other people's program files do not have BOM head, nature will not need to deal with!
And you want to use the primary editor to edit PHP files, but also adhere to the Utf-8 code, which naturally requires you to deal with the BOM head


It's not even a BOM head.

Other people's program files do not have BOM head, nature will not need to deal with!
And you want to use the primary editor to edit PHP files, but also adhere to the Utf-8 code, which naturally requires you to deal with the BOM head


Add a Ob_end_clean (); it'll be all right.
  • Related Article

    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.