Javascript 将json字符串对象转换为json数组 我需要格式化json字符串,使所有名为“children”的节点始终为数组类型 在某些地方,我已经将子元素作为数组类型,但不是在所有地方 如果它已经是数组类型,则无需对其执行任何操作

Javascript 将json字符串对象转换为json数组 我需要格式化json字符串,使所有名为“children”的节点始终为数组类型 在某些地方,我已经将子元素作为数组类型,但不是在所有地方 如果它已经是数组类型,则无需对其执行任何操作,javascript,jquery,json,Javascript,Jquery,Json,输入: "foldChildren": "false", "branchColor": "#000000", "children": [ { "id": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",

输入:

 "foldChildren": "false",
                            "branchColor": "#000000",
                            "children": [
                                {
                                    "id": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",
                                    "parentId": "211c838e-3e2d-4919-ab09-dd7f8a901b97",
                                    "text": {
                                        "caption": "f",
                                        "font": {
                                            "style": "normal",
                                            "weight": "normal",
                                            "decoration": "none",
                                            "size": "15",
                                            "color": "#000000"
                                        }
                                    },
                                    "offset": {
                                        "x": "30",
                                        "y": "93"
                                    },
                                    "foldChildren": "false",
                                    "branchColor": "#000000",
                                    "children": {
                                        "id": "2ecaecb6-d55c-4203-bace-f14e276700af",
                                        "parentId": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",
                                        "text": {
                                            "caption": "x",
                                            "font": {
                                                "style": "normal",
                                                "weight": "normal",
                                                "decoration": "none",
                                                "size": "15",
                                                "color": "#000000"
                                            }
                                        },
                                        "offset": {
                                            "x": "122",
                                            "y": "114"
                                        },
                                        "foldChildren": "false",
                                        "branchColor": "#000000",
                                        "children": ""
                                    }
                                },
预期产出:

 "foldChildren": "false",
                            "branchColor": "#000000",
                            "children": [
                                {
                                    "id": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",
                                    "parentId": "211c838e-3e2d-4919-ab09-dd7f8a901b97",
                                    "text": {
                                        "caption": "f",
                                        "font": {
                                            "style": "normal",
                                            "weight": "normal",
                                            "decoration": "none",
                                            "size": "15",
                                            "color": "#000000"
                                        }
                                    },
                                    "offset": {
                                        "x": "30",
                                        "y": "93"
                                    },
                                    "foldChildren": "false",
                                    "branchColor": "#000000",
                                    "children": [{
                                        "id": "2ecaecb6-d55c-4203-bace-f14e276700af",
                                        "parentId": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",
                                        "text": {
                                            "caption": "x",
                                            "font": {
                                                "style": "normal",
                                                "weight": "normal",
                                                "decoration": "none",
                                                "size": "15",
                                                "color": "#000000"
                                            }
                                        },
                                        "offset": {
                                            "x": "122",
                                            "y": "114"
                                        },
                                        "foldChildren": "false",
                                        "branchColor": "#000000",
                                        "children": []
                                    }]
                                },

伟大的你尝试过什么?我尝试过更换字符串,但并不是所有情况下都成功