当前位置:网站首页>二维格式数组格式索引下标连续问题导致 返回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;
边栏推荐
猜你喜欢
![[translation] modern application load balancing with centralized control plane](/img/b0/22e9bf098d580b2af67255ddcdc0d5.jpg)
[translation] modern application load balancing with centralized control plane

Servlet中数据传到JSP页面使用el表达式${}无法显示问题

线程安全的单例模式

搭建私有云盘 cloudreve

Thread safe singleton mode

easyExcel

Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
![[Flutter] dart: class; abstract class; factory; Class, abstract class, factory constructor](/img/06/ab333a4752de27eae2dd937cf579e2.png)
[Flutter] dart: class; abstract class; factory; Class, abstract class, factory constructor

Detailed analysis of micro service component sentinel (hystrix)

Awk from introduction to earth (0) overview of awk
随机推荐
Distributed transaction solution
Gbase 8C system table PG_ authid
微服务组件Sentinel (Hystrix)详细分析
MUX VLAN Foundation
GBase 8c系统表-pg_conversion
Kotlin middle process understanding and Practice (I)
The use of Flink CDC mongodb and the implementation of Flink SQL parsing complex nested JSON data in monggo
Gbase 8C system table PG_ auth_ members
Choose it when you decide
GBase 8c系统表-pg_amop
Job object of collaboration in kotlin
elastic stack
Gbase 8C system table PG_ collation
[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
Awk from getting started to being buried (2) understand the built-in variables and the use of variables in awk
为什么会选择框架?选择什么样的框架
awk从入门到入土(0)awk概述
GBase 8c系统表-pg_collation
Awk from entry to burial (1) awk first meeting
where 1=1 是什么意思