我的JSON字符串无法通过HTTP GET请求获得完整

when i send my array to my php file it incomplete recive to php file. my arr varible is :

[["╪▒┘à┘╛┘╪د","67126881188552864","Empty,Empty,Empty,Empty,8644,-360,-4,8691,-3
.48,-313,1015,4.334 M,1392/12/28,12:30:08,3.99 M,10 B,10%,530,16.4,16.38,┘à╪ش╪د╪
▓,7,3130,8644,1,50,5000, , , ,8644,11553,359,307,8645,1,1,8655,11
030,2,┌»╪▒┘ê┘ç ┘à┘╛┘╪د (╪│┘ç╪د┘à┘è ╪╣╪د┘à) (╪▒┘à┘╛┘╪د),╪ذ╪د╪▓╪د╪▒ ╪د┘ê┘ (╪ز╪د
╪ذ┘┘ê┘è ╪د╪╡┘┘è) ╪ذ┘ê╪▒╪│ ,connOK"]]

i send data with HTTP GET request like below

    var myJsonString = JSON.stringify(arr);

    page.open('http://localhost/bptest/danger/get.php?data='+myJsonString,function(status){
            console.log("Page opened");
            if (status !== 'success') {
                console.log('FAIL');
            } else {
                console.log("REPLY FROM SERVER:");
                console.log(page.content);
            }});

end my simple php file is below code :

<li><?php echo $_GET["data"]; ?></li>

and php get's this :

[["?????","67126881188552864","Empty,Empty,Empty,Em
pty,8644,-360,-4,8691,-3.48,-313,1015,4.334 M,1392/12/28,12:30:08,3.99 M,10 B,10
%,530,16.4,16.38,????,7,3130,8644,1,50,5000,

why it's crash when recive from php and how i can fix this

Note the <meta charset="utf-8" /> line (and the file itself should be in UTF-8 which should be the default for any decent text editor) and also the use of encodeURIComponent which is when you want to encode something to fit into the query string (since unlike encodeURI, it also encodes characters like & and =).

HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>
var arr = [["╪▒┘à┘╛┘╪د","67126881188552864","Empty,Empty,Empty,Empty,8644,-360,-4,8691,-3\
.48,-313,1015,4.334 M,1392/12/28,12:30:08,3.99 M,10 B,10%,530,16.4,16.38,┘à╪ش╪د╪\
▓,7,3130,8644,1,50,5000,&nbsp;,&nbsp;,&nbsp;,8644,11553,359,307,8645,1,1,8655,11\
030,2,┌»╪▒┘ê┘ç ┘à┘╛┘╪د (╪│┘ç╪د┘à┘è ╪╣╪د┘à) (╪▒┘à┘╛┘╪د),╪ذ╪د╪▓╪د╪▒ ╪د┘ê┘ (╪ز╪د\
╪ذ┘┘ê┘è ╪د╪╡┘┘è) ╪ذ┘ê╪▒╪│ ,connOK"]];
var myJsonString = encodeURIComponent(JSON.stringify(arr));

page.open('http://localhost/bptest/danger/get.php?data='+myJsonString,function(status){
    console.log("Page opened");
    if (status !== 'success') {
        console.log('FAIL');
    } else {
        console.log("REPLY FROM SERVER:");
        console.log(page.content);
    }
});
</script></head><body></body></html>

PHP:

Note the security risk comment (you could also avoid the risk by using "text/plain" as the content-type but then it won't get rendered as HTML if you need that).

<?php
header('Content-type: text/html;charset=utf-8');
echo $_GET['data']; // You better fix this after testing, as it invites XSS scripting attacks!
?>

You must use UTF-8 charset with JSON. Check this points:

  • Header charset
  • Encoding php file with UTF-8
  • Check if receveid data are UTF-8 encoded

I think the charset is not good on one side of your app or is changed during the data transfer.

You must use encodeURI() to encode you json string.

Please see here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI.

Try This

 var myJsonString = JSON.stringify(encodeURI(arr));

    page.open('http://localhost/bptest/danger/get.php?data='+myJsonString,function(status){
            console.log("Page opened");
            if (status !== 'success') {
                console.log('FAIL');
            } else {
                console.log("REPLY FROM SERVER:");
                console.log(page.content);
            }});