【发布时间】:2019-12-19 14:08:09
【问题描述】:
我在本机反应中使用 axios。 postman 中的原始响应如下所示:
{
"id": 2,
"parent_id": 1,
"name": "Default Category",
"is_active": true,
"position": 1,
"level": 1,
"product_count": 2,
"children_data": [
{
"id": 3,
"parent_id": 2,
"name": "Papers",
"is_active": true,
"position": 1,
"level": 2,
"product_count": 2,
"children_data": [
{
"id": 5,
"parent_id": 3,
"name": "A44",
"is_active": true,
"position": 1,
"level": 3,
"product_count": 0,
"children_data": []
}
]
},
{
"id": 6,
"parent_id": 2,
"name": "Laptop",
"is_active": true,
"position": 2,
"level": 2,
"product_count": 1,
"children_data": []
}
]
}
当我尝试这个时如何console.log(typeof categoryResponse.data.children_data);
我得到对象。这会导致问题,因为我正在尝试更新类型数组的 react-native 中的状态变量。甚至打印 console.log(categoryResponse.data); 时的响应对象看起来也很奇怪。
对象{“children_data”:数组[ 目的 { “children_data”:数组 [ 目的 { "children_data": 数组 [], “身份证”:5, “is_active”:是的, “级别”:3, “名称”:“A44”, “父ID”:3, “位置”:1, "product_count": 0, }, ], “身份证”:3, “is_active”:是的, “级别”:2, “名称”:“论文”, “父ID”:2, “位置”:1, “product_count”:2, }, 目的 { "children_data": 数组 [], “身份证”:6, “is_active”:是的, “级别”:2, “名称”:“笔记本电脑”, “父ID”:2, “位置”:2, “product_count”:1, }, ], "id": 2, "is_active": true, "level": 1, "name": "Default Category", "parent_id": 1, "position": 1,
"product_count": 2, }
请帮忙
【问题讨论】:
标签: react-native axios