如何将给定的JSON数组转换为下面给出的更多指定的JSON数组? [英] How do I convert the given JSON array to more specified JSON array given below?
问题描述
<?php
包括'../dbconfig.php';
$ currentbooking =Some Mysqli Query;
$ result = mysqli_query($ link,$ currentbooking);
$ response = array();
while($ row = mysqli_fetch_assoc( $ result))
{
$ response [] = $ row;
}
echo json_encode($回复);
?>
我收到的回复如下
[
{
id:3,
diag_name:LT诊断,
test_name:Alk PO4,
booking_date:2018-05-20
},
{
id:3,
diag_name:LT诊断,
test_name:CRP,
booking_date:2018-05- 20
},
{
id:4,
diag_name: Seepz Diagnostics,
test_name:Alk PO4,
booking_date:2018-05-21
}
]
但是我想在下面写一个更合理的json数组。 />
[
{
diag_name:LT Diagnostics,
test_name:[
{
id:3,
name:Alk PO4
},
{
id:3,
名称:CRP
}
],
booking_date:2018-05-20
},
{
diag_name:Seepz Diagnostics,
test_name:[
{
id:4,
名称:Alk PO4
}
],
booking_date:2018-05-21
},
]
我有什么三编辑:
Plz我不知道如何获取指定的JSON数组.Plz帮助我如何使用它。我想要PHP中指定的JSON格式。
我正在使用Core PHP
<?php
include '../dbconfig.php';
$currentbooking="Some Mysqli Query";
$result = mysqli_query($link, $currentbooking);
$response = array();
while($row = mysqli_fetch_assoc($result))
{
$response[]=$row;
}
echo json_encode($response);
?>
I am getting response as below
[
{
"id": "3",
"diag_name": "LT Diagnostics",
"test_name": "Alk PO4",
"booking_date": "2018-05-20"
},
{
"id": "3",
"diag_name": "LT Diagnostics",
"test_name": "CRP",
"booking_date": "2018-05-20"
},
{
"id": "4",
"diag_name": "Seepz Diagnostics",
"test_name": "Alk PO4",
"booking_date": "2018-05-21"
}
]
But i want a more justified json array written below.
[
{
"diag_name": "LT Diagnostics",
"test_name": [
{
"id": "3",
"name" : "Alk PO4"
},
{
"id": "3",
"name" : "CRP"
}
],
"booking_date": "2018-05-20"
},
{
"diag_name": "Seepz Diagnostics",
"test_name": [
{
"id": "4",
"name" : "Alk PO4"
}
],
"booking_date": "2018-05-21"
},
]
What I have tried:
Plz I don't have any idea how to get the specified JSON array.Plz help me with how to go with it.I want the specified JSON format in PHP.
I am using Core PHP
推荐答案
currentbooking =Some Mysqli Query;
currentbooking="Some Mysqli Query";
result = mysqli_query(
result = mysqli_query(
link,
这篇关于如何将给定的JSON数组转换为下面给出的更多指定的JSON数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!