我通过 JQuery Ajax 从 PHP 返回一个 JSON 多数组,并且想要确定哪个数组包含一个值以便访问该数组中的值(对于其他数组也是如此 - 最多返回三个数组。
$.ajax({
type: "POST",
url: "scripts/get_model_imaging_report.php",
data: {
case_id:caseId,
level:currentLevel
},
dataType: "json",
success: function(returnedData) {
}
});
PHP;
$case = $_POST['case_id'];
$level = $_POST['level'];
$query = "SELECT * FROM model_image_report WHERE case_fk = '$case' AND level = '$level'";
$result = mysql_query($query, $connection) or die(mysql_error());
$data = array();
while ($row = mysql_fetch_array($result)) {
$data[] = array(
'image_report_type' => $row['image_report_type'],
'subject' => $row['subject'],
'clinical' => $row['clinical'],
'study_type' => $row['study_type'],
'report' => $row['report'],
'comment' => $row['comment'],
'image' => $row['image'],
'image_annotated' => $row['image_annotated']
);
}
echo json_encode($data);
我需要检查的关键是“image_report_type”,值可以是“核”、“放射学”和“超声”。
然后,我需要访问例如 'image_report_type' == 'nuclear' 的那些数组中的值。
JSON 数组如下所示:
[{"image_report_type":"nuclear","subject":"Brain Scan","clinical":"Clinical","study_type":"nuclear image scan.","report":"Report","comment":"Comment","image":"original_image_case_3_level_1_nuclear.jpg","image_annotated":"annotated_image_case_3_level_1_nuclear.png"},{"image_report_type":"ultrasound","subject":"Brain Scan","clinical":"Clinical","study_type":"Ultrasound image scan.","report":"Report","comment":"Comment","image":"original_image_case_3_level_1_nuclear.jpg","image_annotated":"annotated_image_case_3_level_1_nuclear.png"}]