在我的脚本中json_enocode是编码字符串还是可能还有其他一些问题?
首先让我展示我在配置和代码中的所有内容
表格结构
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
这是我在给定表格的一行中更新的字符串
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 = "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);
编码$ r后我得到了这个输出
[{“songs_id”:“2”,“lyrics”:null,“username”:“bhavik”,“song_name”:“some name 1”,“fullname”:“Bhavik Thakor Garasiya”} ]
更新:
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 ) )
答案 0 :(得分:0)
我已经运行了一些测试,这个字符’
似乎打破了json enconding的文本。
这是我用来测试数据的脚本。第一部分尝试按提供的方式对文本进行编码,然后将’
字符替换为'
,并且编码可以正常工作。
<?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 "\n";
$json['data'] = str_replace('’', "'", $json['data']);
echo json_encode($json);
echo '</pre>';
?>
这是输出:
{"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\r\n\r\nWe 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.\r\n\r\n You will not post content that is copyrighted or Unauthorized\r\n You will not use someone's account\r\n You will not irritate users in anyways.\r\n You will not upload content like virus or spam.\r\n You will not share content that can hate someone, threatening, or pornographic.\r\n You will not do act that can affect this web site.\r\n You must provide all your original details.\r\n You will not use, download or share someone's content like personal information, photographs, videos or any other that is not yours.\r\n You will not force user to do act that make our samaj down.\r\n You will not force user to fight against your enemy.\r\n You will not encourage people to do violence.\r\n You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. "}