php转换成json数据格式是怎么转换的?
{"programmers":[{"firstName":"Brett","lastName":"McLaughlin","email":"aaaa"},{"firstN...
{ "programmers": [ { "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },
{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },
{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
],
"authors": [
{ "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
{ "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
{ "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
],
"musicians": [
{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
{ "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
] }
这样的数据格式是怎么样转换的 展开
{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" },
{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }
],
"authors": [
{ "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
{ "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
{ "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
],
"musicians": [
{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
{ "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
] }
这样的数据格式是怎么样转换的 展开
1个回答
推荐于2019-08-09 · 知道合伙人软件行家
关注
展开全部
其实就是把这3个结果并成一个数组,再转就是了
例如,
$res1=mysql_query($sql1);
$res2=mysql_query($sql2);
$res3=mysql_query($sql3);
定义一个新的数组 $a = array();
将3个结果压入这个新的数组
array_push($a,$res1);
array_push($a,$res2);
array_push($a,$res3);
最后转义输出
echo json_encode($a);
LZ遇到问题不要气馁呀
例如,
$res1=mysql_query($sql1);
$res2=mysql_query($sql2);
$res3=mysql_query($sql3);
定义一个新的数组 $a = array();
将3个结果压入这个新的数组
array_push($a,$res1);
array_push($a,$res2);
array_push($a,$res3);
最后转义输出
echo json_encode($a);
LZ遇到问题不要气馁呀
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询