素材牛VIP会员
JSON 数据拆分
 BO***OS  分类:JavaScript  人气:925  回帖:1  发布于6年前 收藏

这是在数据提交时遇到的问题。

我准备提交的数据结构是这样的:

    {
        "path": "test",
        "clients": [
            {
                "client": "1.2.2.2;1.1.1.1",
                "Access_Type": 2,
                "name": "test_01"
            },
            {
                "client": "1.2.2.4;1.1.1.4",
                "Access_Type": 1,
                "name": "test_02"
            },
            {
                "client": "1.3.3.3",
                "Access_Type": 1,
                "name": "test_03"
            }
        ]
    }

而需要提交的数据的结构是这样的:

    {
        "path": "test",
        "clients": [
            {
                "client": "1.2.2.2",
                "Access_Type": 2,
                "name": "test_01"
            },
            {
                "client": "1.1.1.1",
                "Access_Type": 2,
                "name": "test_01"
            },
            {
                "client": "1.2.2.4",
                "Access_Type": 1,
                "name": "test_02"
            },
            {
                "client": "1.1.1.4",
                "Access_Type": 1,
                "name": "test_02"
            },
            {
                "client": "1.3.3.3",
                "Access_Type": 1,
                "name": "test_03"
            }
        ]
    }

注:client对应的字段,如果是多条并以“;”分隔,则做拆分处理,单条则不处理。

对于这种JSON数据结构的拆分,大家有什么解决方案,希望指教一下!

讨论这个帖子(1)垃圾回帖将一律封号处理……

Lv1 新人
风***扬 Web前端工程师 6年前#1
 文明上网,理性发言!   😉 阿里云幸运券,戳我领取