由于某种原因,json_encode没有封装有效json的密钥?
$json = array(); for($i=0;$i<count($result);$i++){ $datum = $result[$i]; $mid = $datum->mid; $desc = $datum->description; $score = $datum->score; $json[$i] = array("desc"=>$desc,"score"=>$score); } $json = json_encode($json, JSON_PRETTY_PRINT ); echo $json;
输出为
[ { desc: "audio receiver", score: 0.81596649 }, { desc: "gadget", score: 0.69863933 } ]
但desc
和score
应为"desc"
和"score"
以获得正确的jsonlint