ホームページ >バックエンド開発 >PHPチュートリアル >ヘルプ! ! php+ajax+jsonの問題
function gtou($s) { return iconv('gbk', 'utf-8', $s); }$proquery ="select * from pro where typeid='".$id."' order by corank asc"; $dsql->SetQuery($proquery); $dsql->Execute(); $a=array(); while($row = $dsql->GetArray()) { $a[]= array_map('gtou', $row); } $res = array( "status" => "1", "result" => $a, "moreUrl" => $moreurl, ); echo json_encode($res);
print_r($a); 見てください
Array ( [0] => Array ( [id] => 1 [グッズタイトル] =>??????寰?ˉ姘? [グッズURL] =>アップロード/allimg/c131205/13V23912150-114L_lit.jpg [ブランドタイトル] => [ブランドurl] => http://www.ecoo.com.cn/dsadasdas/ [imgurl] => //www.ecoo.com.cn/sadas213/ [価格] => 59.9 ) [1] => Array ( [id] => 2 [goodstitle] => チェンユ プレス Suo??222 [goodsurl] ] => http://www.ecoo.com.cn/uploads/allimg/13V23912150-114L_lit.jpg [ブランドタイトル] =>?222 [ブランドURL] => com.cn/dsadasdas/ [imgurl] = > http://www.ecoo.com.cn/sadas213/ [価格] => 59.9 ) )
これは var_dump
array(2) { の結果です[0]=> array(7) { [ "id"]=> string(1) "1" ["goodstitle"]=> string(54) "曛ユプレス娑?????? ??寰?ソ寰?ˉ姘???? ?ridge??" ["goodsurl"]=> string(70) "http://www.ecoo.com.cn/uploads/allimg/c131205/ 13V23912150-114L_lit.jpg" ["brandtitle"]=> string(9) "Ti????" ["brandurl"]=> string(33) "http://www.ecoo.com.cn/ dsadasdas/" ["imgurl"]=> 文字列(32 ) "http://www.ecoo.com.cn/sadas213/" ["価格"]=> 文字列(4) "59.9" } [1] => array(7) { ["id"]= > string(1) "2" ["goodstitle"]=> string(15) "琛ユプレス??222" ["goodsurl"]= > 文字列(70) "http://www.ecoo .com.cn/uploads/allimg/c131205/13V23912150-114L_lit.jpg" ["ブランドタイトル"]=> 文字列(6) "Ti?222" [" brandurl"]=> string(33) "http://www.ecoo.com.cn/dsadasdas/" ["imgurl"]=> string(32) "http://www.ecoo.com.cn /sadas213/" ["price"]=> string( 4) "59.9" } }
$a を
$a = array ( array( "id" => "1102444","title"=>"事实上","goodstitle"=>"事实上","price"=>"429.0","imgurl"=>".jpg","goodsurl"=>"/","brandtitle"=>"44444","brandurl"=>"_share/" ), array( "id" => "1102444","title"=>"赌东道的","goodstitle"=>"赌东道的","price"=>"429.0","imgurl"=>"0.jpg","goodsurl"=>"2444/","brandtitle"=>"7777","brandurl"=>"share/" ) );に置き換えると、結果は空ではありません。データを読み取るときにも変換できるとのことですが、ずっと探していました
$a 在函数中,你调用了吗。函数的return 也不对吧?
谢谢 大神们的支持 由于小弟疏忽
在AJAX请求时 路径写错
其他啥问题都没有
结贴!!!
function gtou($s) { return iconv('gbk', 'utf-8', $s); }$a = array ( array( "id" => "1102444","title"=>"事实上","goodstitle"=>"事实上","price"=>"429.0","imgurl"=>".jpg","goodsurl"=>"/","brandtitle"=>"44444","brandurl"=>"_share/" ), array( "id" => "1102444","title"=>"赌东道的","goodstitle"=>"赌东道的","price"=>"429.0","imgurl"=>"0.jpg","goodsurl"=>"2444/","brandtitle"=>"7777","brandurl"=>"share/" ) );foreach($a as $r) $t[] = array_map('gtou', $r);$moreurl = 'x';$res = array( "status" => "1", "result" => $t, "moreUrl" => $moreurl, ); echo json_encode($res);{"status":"1","result":[{"id":"1102444","title":"\u4e8b\u5b9e\u4e0a","goodstitle":"\u4e8b\u5b9e\u4e0a","price":"429.0","imgurl":".jpg","goodsurl":"\/","brandtitle":"44444","brandurl":"_share\/"},{"id":"1102444","title":"\u8d4c\u4e1c\u9053\u7684","goodstitle":"\u8d4c\u4e1c\u9053\u7684","price":"429.0","imgurl":"0.jpg","goodsurl":"2444\/","brandtitle":"7777","brandurl":"share\/"}],"moreUrl":"x"}