Jquery 从mysql输出正确的复杂json格式

Jquery 从mysql输出正确的复杂json格式,jquery,json,Jquery,Json,当我试图从mysql输出复杂json的记录以发送回jquery时,我遇到了问题 我的桌子 bil iduser name experience 0 001 jacobs bus driver 1 002 max painter 2 001 jacobs racing driver 3 003 john engineer 4 001

当我试图从mysql输出复杂json的记录以发送回jquery时,我遇到了问题

我的桌子

bil    iduser     name      experience
0       001       jacobs    bus driver 
1       002       max       painter
2       001       jacobs    racing driver
3       003       john      engineer
4       001       jacobs    retiree
5       002       max       designer
6       003       john      senior engineer
结果应该是

[
    {
        "iduser":001,
        "name":"jacobs", 
        "exprience":[{"exp":"bus driver"},{"exp":"racing driver"},{"exp":"retiree"}]
    },
    {
        "iduser":002,
        "name":"max", 
        "exprience":[{"exp":"painter"},{"exp":"designer"}]
    }
]
我对简单的json格式没什么意见,但是这种复杂的格式我完全失败了,我被困在这里了


希望有人能告诉我如何使用php格式化它。首先,使用


然后使用

vimalnath将数组转换为JSON格式,对于单个记录,我同意……但是对于重复值,此处有点丢失……显示查询和数组结果。dqlopez此处$JSON=array$expArr=数组$db=数据库::getInstance;ifis_object$db{$sqlSelect=SELECT*FROM sometable;$row=$db->executeGrab$sqlSelect;ifis_array$row{$len=count$row;if$len>0{for$i=0;$i$row[$i]['experience'];}$dataArr=array'IDUSER'=>$row[0]['IDUSER'],'NAME'=>row[0]['NAME'],'exprience'=>expArr;array_推送$json,$dataArr;}{//echo NONE DATA;}}其他ifis_bool$row{//echo bool;}}echo json_encode$json;