php api jsonencoding结果使Intiger键为字符串[0] => val输出“ 0”:val

时间:2018-07-11 07:59:14

标签: php api jsonencoder

$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)]["is_decoration"]="true";                                                                                                
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]["image"]='';                                            
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]["bottom_right_x"]=$vv["bottom_right_x"];
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]['bottom_right_y']=$vv["bottom_right_y"];
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]['top_right_x']=$vv["top_right_x"];
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]['top_right_y']=$vv["top_right_y"];
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]['top_left_x']=$vv["top_left_x"];
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]['top_left_y']=$vv["top_left_y"];
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]['bottom_left_x']=$vv["bottom_left_x"];
$data['frame']["CollageDecoration"]["ClgD".$this->actionApiNumToWord($i+1)][$j]['bottom_left_y']=$vv["bottom_left_y"];

echo json_encode($data, JSON_UNESCAPED_SLASHES);

输出:

"ClgDFour": {   // this 0 is integer but it give "0" like string index
                "0": {
                    "image": "",
                    "bottom_right_x": "0.6973036342321218",
                    "bottom_right_y": "0.5270833333333333",
                    "top_right_x": "0.6973036342321218",
                    "top_right_y": "0.32708333333333334",
                    "top_left_x": "0.5885111371629543",
                    "top_left_y": "0.32708333333333334",
                    "bottom_left_x": "0.5885111371629543",
                    "bottom_left_y": "0.5270833333333333"
                },
                "is_decoration": "true"
            }

1 个答案:

答案 0 :(得分:0)

JSON密钥必须是字符串。这就是为什么它是输出中的字符串。

阅读here,以了解有关JSON对象的更多信息。