当前位置:网站首页>二维格式数组格式索引下标连续问题导致 返回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;
边栏推荐
- [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)
- QT qcombobox add qccheckbox (drop-down list box insert check box, including source code + comments)
- 通达OA 首页门户工作台
- [codeforces] cf1338a - Powered addition [binary]
- Awk from entry to burial (1) awk first meeting
- How to change the panet layer in yolov5 to bifpn
- [translation] flux is safe. Gain more confidence through fuzzy processing
- Monitoring and management of JVM
- [fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
- Packing and unpacking of JS
猜你喜欢

SPI机制

通达OA 首页门户工作台

Create + register sub apps_ Define routes, global routes and sub routes

Thread safe singleton mode

PyTorch 卷积网络正则化 DropBlock

Detailed introduction to the usage of Nacos configuration center

Use go language to realize try{}catch{}finally
![[hcia]no.15 communication between VLANs](/img/59/a467c5920cbccb72040f39f719d701.jpg)
[hcia]no.15 communication between VLANs
![[translation] the background project has joined the CNCF incubator](/img/0b/e3d2674b1a1cba3ea398cbcb1a018a.png)
[translation] the background project has joined the CNCF incubator
![[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)](/img/6a/ae44ddb090ce6373f04a550a15f973.jpg)
[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)
随机推荐
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
返回一个树形结构数据
【CodeForces】CF1338A - Powered Addition【二进制】
简单理解svg
Gbase 8C function / stored procedure definition
[advanced ROS] Lesson 6 recording and playback in ROS (rosbag)
线程安全的单例模式
require. context
怎么将yolov5中的PANet层改为BiFPN
Cvpr2022 remove rain and fog
The use of Flink CDC mongodb and the implementation of Flink SQL parsing complex nested JSON data in monggo
5.文件操作
JS的装箱和拆箱
The data in servlet is transferred to JSP page, and the problem cannot be displayed using El expression ${}
[translation] modern application load balancing with centralized control plane
Gbase 8C system table PG_ attribute
Word word word
Job object of collaboration in kotlin
The Sandbox阐释对元宇宙平台的愿景
Kotlin middle process understanding and Practice (I)