当前位置:网站首页>二维格式数组格式索引下标连续问题导致 返回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;
边栏推荐
- Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
- What does "where 1=1" mean
- 【教程】chrome關閉跨域策略cors、samesite,跨域帶上cookie
- [hcia]no.15 communication between VLANs
- Gbase 8C system table PG_ amop
- [Yu Yue education] China Ocean University job search OMG reference
- Mathematical statistics -- Sampling and sampling distribution
- Qt之QComboBox添加QCheckBox(下拉列表框插入复选框,含源码+注释)
- Gbase 8C create user / role example 2
- 【翻译】后台项目加入了CNCF孵化器
猜你喜欢
![[translation] modern application load balancing with centralized control plane](/img/b0/22e9bf098d580b2af67255ddcdc0d5.jpg)
[translation] modern application load balancing with centralized control plane

The data in servlet is transferred to JSP page, and the problem cannot be displayed using El expression ${}

Producer consumer model based on thread pool (including blocking queue)

easyPOI

The use of Flink CDC mongodb and the implementation of Flink SQL parsing complex nested JSON data in monggo

4. Classes and objects

Coroutinecontext in kotlin

Detailed introduction to the deployment and usage of the Nacos registry

通达OA 首页门户工作台

Build a private cloud disk cloudrev
随机推荐
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
Interview stereotyped version
Awk from getting started to getting into the ground (3) the built-in functions printf and print of awk realize formatted printing
GBase 8c系统表-pg_authid
awk从入门到入土(2)认识awk内置变量和变量的使用
Gbase 8C function / stored procedure parameters (I)
为什么会选择框架?选择什么样的框架
GBase 8c 函数/存储过程参数(二)
Awk from entry to burial (1) awk first meeting
Detailed analysis of micro service component sentinel (hystrix)
QT qcombobox add qccheckbox (drop-down list box insert check box, including source code + comments)
Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque
[translation] the background project has joined the CNCF incubator
GBase 8c系统表pg_cast
GBase 8c系统表-pg_am
Compréhension simple de SVG
What does "where 1=1" mean
cvpr2022去雨去雾
awk从入门到入土(1)awk初次会面
面试项目技术栈总结