gpt4 book ai didi

php - 在php中输出json数组

转载 作者:行者123 更新时间:2023-12-04 21:53:09 28 4
gpt4 key购买 nike

我目前有这个 json :

{"quest_id":"1","quest_title":"Buy 3 pints of draft and a large pizza and then get desert","quest_price":"15","quest_points":"100"}{"quest_id":"2","quest_title":"Hello WOrld","quest_price":"50","quest_points":"10"}

我想知道如何输出这个:

{"quests":  {"quest_id":"1","quest_title":"Buy 3 pints of draft and a large pizza and then get desert","quest_price":"15","quest_points":"100"}{"quest_id":"2","quest_title":"Hello WOrld","quest_price":"50","quest_points":"10"}
}

这是php中的代码:

while($result=mysql_fetch_array($number, MYSQL_ASSOC)){
print(json_encode($result));

}

最佳答案

试试这个:

$result = array('quests' => array());
while($row = mysql_fetch_array($number, MYSQL_ASSOC)){
$result['quests'][] = $row
}
echo json_encode($result);

关于php - 在php中输出json数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8706008/

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