gpt4 book ai didi

javascript - 将 JSON 数组中的字符串元素解析为整数

转载 作者:行者123 更新时间:2023-11-30 12:30:36 27 4
gpt4 key购买 nike

 $con = new DBConnector();
$sth = $con->Query("SELECT medicinename as label, factor as data FROM medicine_master_tbl limit 4");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
echo json_encode($rows);

我的查询没有问题,但是返回值是..

[{"label":"rrp","data":"5"},{"label":"t","data":"34"},{"label":"tt","data":"4"},{"label":"nutrachin","data":"45"}]

我需要如下所示的 json 数组..

[{"label":"rrp","data":5},{"label":"t","data":34},{"label":"tt","data":4},{"label":"nutrachin","data":45}]

数据在这个数组中被视为字符串,我需要将其解析为整数..在此先感谢。

最佳答案

一个简单的。

while ($r = mysql_fetch_assoc($sth)) {
$r["data"] = intval($r["data"]);
$rows[] = $r;
}

关于javascript - 将 JSON 数组中的字符串元素解析为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27836673/

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