gpt4 book ai didi

php - 格式 echo json_encode

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:53:05 27 4
gpt4 key购买 nike

<分区>

我想格式化echo json_encode,目前输出是

{"results":{"course":"CC140","books":{"book":[[{"id":"300862","title":"Building object-oriented software","isbn":"0070431965","borrowedcount":"6"}]]}}}

而我想这样输出:

{
"results": {
"course": "CC140",
"books": {
"book": [
[
{
"id": "300862",
"title": "Building object-oriented software",
"isbn": "0070431965",
"borrowedcount": "6"
}
]
]
}
}
}

这是生成 JSON 的代码

$temp = array();
foreach ($my_array as $counter => $bc) {
$temp['id'] = "$id[$counter]";
$temp['title'] = "$title[$counter]";
$temp['isbn'] = "$isbn[$counter]";
$temp['borrowedcount'] = "$borrowedcount[$counter]";
$t2[] = $temp;
}

$data = array(
"results" => array(
"course" => "$cc",
"books" => array(
"book" =>
array(
$t2
)
)
)
);
echo json_encode($data);

任何帮助或指点将不胜感激,谢谢

添加这个

header('Content-type: application/json');
echo json_encode($data, JSON_PRETTY_PRINT);

格式化 JSON,但 header 也超出了整个 HTML 文档

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com