当前位置:网站首页>二维格式数组格式索引下标连续问题导致 返回json 格式问题
二维格式数组格式索引下标连续问题导致 返回json 格式问题
2022-07-03 02:31:00 【qq_27878777】
1. 数组下标连续 返回json 格式不带索引
[
0=>[
'id'=>1,
'title'=>'测试一',
],
1=>[
'id'=>1,
'title'=>'测试一',
],
2=>[
'id'=>1,
'title'=>'测试一',
],
]
{
"msg": "ok",
"data": [
{
"id": 1,
"title": "测试一"
},
{
"id": 1,
"title": "测试一"
},
{
"id": 1,
"title": "测试一"
}
]
}
2. 数组下标不连续 , 返回json格式带索引
[
0=>[
'id'=>1,
'title'=>'测试一',
],
2=>[
'id'=>1,
'title'=>'测试一',
],
5=>[
'id'=>1,
'title'=>'测试一',
],
];
{
"msg": "ok",
"data": {
"0": {
"id": 1,
"title": "测试一"
},
"2": {
"id": 1,
"title": "测试一"
},
"5": {
"id": 1,
"title": "测试一"
}
}
}
3. 解决办法 重置索引连续
//重置连续索引
$lst = array_slice($lst, 0, count($lst), false);
return $lst;
边栏推荐
猜你喜欢
【翻译】后台项目加入了CNCF孵化器
【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
Tongda OA V12 process center
Coroutinecontext in kotlin
[hcia]no.15 communication between VLANs
Oauth2.0 authentication, login and access "/oauth/token", how to get the value of request header authorization (basictoken)???
线程安全的单例模式
错误Invalid bound statement (not found): com.ruoyi.stock.mapper.StockDetailMapper.xxxx解决
RestCloud ETL 跨库数据聚合运算
Principle and application of database
随机推荐
4. 类和对象
Cancellation of collaboration in kotlin, side effects of cancellation and overtime tasks
[translation] flux is safe. Gain more confidence through fuzzy processing
awk从入门到入土(2)认识awk内置变量和变量的使用
GBase 8c触发器(二)
GBase 8c系统表-pg_amop
The data in servlet is transferred to JSP page, and the problem cannot be displayed using El expression ${}
Oauth2.0 authentication, login and access "/oauth/token", how to get the value of request header authorization (basictoken)???
Gbase 8C function / stored procedure parameters (II)
Gbase 8C system table PG_ auth_ members
Awk from entry to burial (1) awk first meeting
Detailed introduction to the deployment and usage of the Nacos registry
Producer consumer model based on thread pool (including blocking queue)
GBase 8c系统表-pg_constraint
JS的装箱和拆箱
【翻译】Flux安全。通过模糊处理获得更多信心
基于线程池的生产者消费者模型(含阻塞队列)
Job object of collaboration in kotlin
[Hcia]No.15 Vlan间通信
Apple releases MacOS 11.6.4 update: mainly security fixes