PHP로 새롭게 변경되었습니다. JSON 형식을 지정하려고합니다.PHP 웹 서비스 형식의 json 형식
$query = mysql_query("SELECT *
FROM `micards` m
JOIN user u ON m.`mobile` = u.phone");
while ($row = mysql_fetch_assoc($query)) {
$response["success"] = 1;
$name = array('name'=>$row["name"],'email'=>$row["email"],'mobile'=>$row["mobile"]);
$phone[] = array('phone'=>$row["phone"],array('card'=>$name));
$response["contacts"] = $phone;
}
echo json_encode($response);
내가이 출력 받고 있어요 :
{
"success": 1,
"contacts": [{
"phone": "919898989898",
"0": {
"card": {
"name": "abcd",
"email": "[email protected]",
"mobile": "919898989898"
}
}
}, {
"phone": "919898989898",
"0": {
"card": {
"name": "abcd",
"email": "[email protected]",
"mobile": "919898989898"
}
}
}, {
"phone": "8686868686",
"0": {
"card": {
"name": "pan",
"email": "[email protected]",
"mobile": "8686868686"
}
}
}, {
"phone": "8686868686",
"0": {
"card": {
"name": "monk",
"email": "[email protected]",
"mobile": "8686868686"
}
}
}]
}
을하지만 난이 원하는 : 여기에 관련 코드는
{
"success": 1,
"contacts": [{
"phone": "919898989898",
{
"card": {
"name": "abcd",
"email": "[email protected]",
"mobile": "919898989898"
}
},
{
"card": {
"name": "abcd",
"email": "[email protected]",
"mobile": "919898989898"
}
}
}],
[{
"phone": "8686868686",
{
"card": {
"name": "panky",
"email": "[email protected]",
"mobile": "8686868686"
}
},
{
"card": {
"name": "panky",
"email": "[email protected]",
"mobile": "8686868686"
}
}
}]
}
나는 위의 출력을 얻기 위해 무엇을 할 수 있는가?
여러분 모두를위한 감사합니다. 그러나 위의 솔루션을 사용하지 않습니다 – user3395570