以下 PHP 返回一个无效的 json:
$sql = 'select * from website where websiteID = "'. $websiteID .'"';
$q = mysql_query( $sql ) or die(mysql_error());
$res = json_encode( mysql_fetch_assoc($q) );
echo $res;
这是从浏览器复制的json:
{"websiteID":"162","userID":"235","URL":"coucou","themeID":"1","telephone":"","websiteTitle":"","description" :"","keywords":"","nomEntreprise":"","adresse":"","email":"","Page1Title1":"parameter1","Page1Title2":"parameter2","Page1Title3 ":"parameter3","Page1Title4":"parameter4","Page1Title5":"parameter5","page1Title6":"parameter6","page1Title7":"parameter7","page1Title8":"parameter8","page1Title9": "参数9","page1Title10":"parameter10","Page1Text1":"parameter11","Page1Text2":"parameter12","Page1Text3":"parameter13","Page1Text4":"parameter14","Page1Text5":"parameter15","Page1Text6":"parameter16" ,"Page1Text7":"parameter17","Page1Text8":"parameter18","Page1Text9":"parameter19","Page1Text10":"parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20 parameter20参数20 参数20 参数20 参数20 参数20 参数20 参数20 ","Page1Text11":"parameter21","Page1Text12":"parameter22","Page1Text13":"parameter23","Page1Text14":"parameter24","Page1Text15":"parameter25","Page1Text16":"parameter26","Page1Text17":"", "Page1Text18":"","Page1Text19":"","Page2Title1":""}
如何解决此问题并传递有效的 json 输出?
显然json是有效的。出于某种原因,从浏览器复制到http://jsonlint.com/时出现错误。