douyue6520 2012-10-25 18:33
浏览 92

json_encode不编码长字符串

in my script json_enocode is encoding string or there may be some other problem ?

first Let me show all things that i have in my configuration and codes

table structure

CREATE TABLE `dc_songs` (
 `songs_id` int(11) NOT NULL AUTO_INCREMENT,
 `username` varchar(50) NOT NULL,
 `song_name` varchar(2000) NOT NULL,
 `lyrics` text NOT NULL,
 `created_time` datetime NOT NULL,
 `is_deleted` tinyint(4) NOT NULL,
 `delete_reason` text NOT NULL,
 PRIMARY KEY (`songs_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1

Here is string that i have updated in one row of given table

UPDATE `dc_songs` SET `lyrics` = 'Your account privacy is very important to us. You are like our family member. You can manage all your content via privacy settings. Content with privacy settings public visible to every user of this web site. You must read how content will be displayed according to your privacy in Help Section. 2.Safety

We do our best keep this web site safe but this not always depend on us, for that you will need to follow this safety Rules.

    You will not post content that is copyrighted or Unauthorized
    You will not use someone’s account
    You will not irritate users in anyways.
    You will not upload content like virus or spam.
    You will not share content that can hate someone, threatening, or pornographic.
    You will not do act that can affect this web site.
    You must provide all your original details.
    You will not use, download or share someone’s content like personal information, photographs, videos or any other that is not yours.
    You will not force user to do act that make our samaj down.
    You will not force user to fight against your enemy.
    You will not encourage people to do violence.
    You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. ' WHERE `dc_songs`.`songs_id` = 2;

query i am using

$query = "SELECT songs_id,lyrics,s.username,song_name,p.fullname
            FROM dc_songs s
            LEFT JOIN profile p ON p.username=s.username
            ORDER by songs_id DESC";
        $r=$db->run($query);

after encoding $r i am getting this output

[{"songs_id":"2","lyrics":null,"username":"bhavik","song_name":"some name 1","fullname":"Bhavik Thakor Garasiya"}]

UPDATE :

output of print_r($r);

Array ( [0] => Array ( [songs_id] => 2 [lyrics] => Your account privacy is very important to us. You are like our family member. You can manage all your content via privacy settings. Content with privacy settings public visible to every user of this web site. You must read how content will be displayed according to your privacy in Help Section. 2.Safety We do our best keep this web site safe but this not always depend on us, for that you will need to follow this safety Rules. You will not post content that is copyrighted or Unauthorized You will not use someone’s account You will not irritate users in anyways. You will not upload content like virus or spam. You will not share content that can hate someone, threatening, or pornographic. You will not do act that can affect this web site. You must provide all your original details. You will not use, download or share someone’s content like personal information, photographs, videos or any other that is not yours. You will not force user to do act that make our samaj down. You will not force user to fight against your enemy. You will not encourage people to do violence. You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. [username] => bhavik [song_name] => some name 1 [fullname] => Bhavik Thakor Garasiya ) ) 
  • 写回答

1条回答 默认 最新

  • dongshi1207 2012-10-25 18:58
    关注

    I've run some tests and this character seems to be breaking the json enconding for the text.

    Here's the script I used to test the data. The first part tries to encode the text as provided, then the character is replaced by ' and the encoding works.

    <?php
    $json = array('data' => htmlentities('Your account privacy is very important to us. You are like our family member. You can manage all your content via privacy settings. Content with privacy settings public visible to every user of this web site. You must read how content will be displayed according to your privacy in Help Section. 2.Safety
    
    We do our best keep this web site safe but this not always depend on us, for that you will need to follow this safety Rules.
    
        You will not post content that is copyrighted or Unauthorized
        You will not use someone’s account
        You will not irritate users in anyways.
        You will not upload content like virus or spam.
        You will not share content that can hate someone, threatening, or pornographic.
        You will not do act that can affect this web site.
        You must provide all your original details.
        You will not use, download or share someone’s content like personal information, photographs, videos or any other that is not yours.
        You will not force user to do act that make our samaj down.
        You will not force user to fight against your enemy.
        You will not encourage people to do violence.
        You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. '));
    
    echo '<pre>';
    echo json_encode($json);
    echo "
    ";
    
    $json['data'] = str_replace('’', "'", $json['data']);
    
    echo json_encode($json);
    echo '</pre>';
    ?>
    

    Here's the output:

    {"data":null}
    {"data":"Your account privacy is very important to us. You are like our family member. You can manage all your content via privacy settings. Content with privacy settings public visible to every user of this web site. You must read how content will be displayed according to your privacy in Help Section. 2.Safety
    
    We do our best keep this web site safe but this not always depend on us, for that you will need to follow this safety Rules.
    
        You will not post content that is copyrighted or Unauthorized
        You will not use someone's account
        You will not irritate users in anyways.
        You will not upload content like virus or spam.
        You will not share content that can hate someone, threatening, or pornographic.
        You will not do act that can affect this web site.
        You must provide all your original details.
        You will not use, download or share someone's content like personal information, photographs, videos or any other that is not yours.
        You will not force user to do act that make our samaj down.
        You will not force user to fight against your enemy.
        You will not encourage people to do violence.
        You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. "}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog