php 打印 json 数组

按序列类型:

<?php
header('Content-type:application/json;charset=utf-8');
  // 索引数组
  $i= array("hexingxing","24","male",["music","UX/UE","game"],"hexingxing.cn","it@hexingxing.cn");
  echo json_encode($i, JSON_FORCE_OBJECT);
?>

打印结果:

{"0":"hexingxing","1":"24","2":"male","3":{"0":"music","1":"UX\/UE","2":"game"},"4":"hexingxing.cn","5":"it@hexingxing.cn"}

调用数据:

{略}

指定 ID 类型:

<?php
header('Content-type:application/json;charset=utf-8');
  // 索引数组
  $i= array('nane'=>'hexingxing','age'=>'24','gender'=>'male','like'=>['music','UX/UE','game'],'web'=>'hexingxing.cn','email'=>'it@hexingxing.cn');
  echo json_encode($i, JSON_FORCE_OBJECT);
?>

打印结果:

{"nane":"hexingxing","age":"24","gender":"male","like":{"0":"music","1":"UX\/UE","2":"game"},"web":"hexingxing.cn","email":"it@hexingxing.cn"}

调用数据:

{略}

0 条评论

昵称

沙发空缺中,还不快抢~