php - json_encode引用封装密钥

时间:2016-02-28 03:03:45

标签: php json

由于某种原因,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
} 
]

descscore应为"desc""score"以获得正确的jsonlint

0 个答案:

没有答案