在nlohamnn库中对数组数据进行提取

github中该问题的链接:issue

the json file is:

{
    "response": {
        "count": 246,
        "items": [
            {
                "id": 456239356,
                "album_id": -15,
                "owner_id": 223134400,
                "sizes": [
                    {
                        "type": "m",
                        "url": "https://sun9-25.u...4c5/FPhcIYb3UH0.jpg",
                        "width": 97,
                        "height": 130
                    },
                    {
                        "type": "o",
                        "url": "https://sun9-41.u...4c7/JDqz1u_L8p4.jpg",
                        "width": 130,
                        "height": 173
                    },
                    {
                        "type": "p",
                        "url": "https://sun9-61.u...4c8/DB5DZsOldK4.jpg",
                        "width": 200,
                        "height": 267
                    },
                    {
                        "type": "q",
                        "url": "https://sun9-4.us...4c9/ckrBy4eD8-c.jpg",
                        "width": 320,
                        "height": 427
                    },
                    {
                        "type": "r",
                        "url": "https://sun9-10.u...4ca/YMxebK1MdXE.jpg",
                        "width": 450,
                        "height": 600
                    },
                    {
                        "type": "s",
                        "url": "https://sun9-14.u...4c4/3SBIzASVRfg.jpg",
                        "width": 56,
                        "height": 75
                    },
                    {
                        "type": "x",
                        "url": "https://sun9-43.u...4c6/M2kNQnDOHEU.jpg",
                        "width": 450,
                        "height": 600
                    }
                ],
                "text": "",
                "date": 1531926387
            },
            {
                "id": 456239361,
                "album_id": -15,
                "owner_id": 223134400,
                "sizes": [
                    {
                        "type": "m",
                        "url": "https://sun9-47.u...1b6/diTkAYuSeEY.jpg",
                        "width": 97,
                        "height": 130
                    },
                    {
                        "type": "o",
                        "url": "https://sun9-5.us...1bb/UJd8Jlha1Ow.jpg",
                        "width": 130,
                        "height": 173
                    },
                    {
                        "type": "p",
                        "url": "https://sun9-49.u...1bc/FF8SEu_oBt0.jpg",
                        "width": 200,
                        "height": 267
                    },
                    {
                        "type": "q",
                        "url": "https://sun9-47.u...1bd/hXZmMKhYgFw.jpg",
                        "width": 320,
                        "height": 427
                    },
                    {
                        "type": "r",
                        "url": "https://sun9-37.u...1be/dcyHZoEEfBQ.jpg",
                        "width": 510,
                        "height": 680
                    },
                    {
                        "type": "s",
                        "url": "https://sun9-28.u...1b5/hW5bO1WXZ04.jpg",
                        "width": 56,
                        "height": 75
                    },
                    {
                        "type": "w",
                        "url": "https://sun9-31.u...1ba/m3ZFNMnSdUg.jpg",
                        "width": 1620,
                        "height": 2160
                    },
                    {
                        "type": "x",
                        "url": "https://sun9-54.u...1b7/Tzx4N7wD3YE.jpg",
                        "width": 453,
                        "height": 604
                    },
                    {
                        "type": "y",
                        "url": "https://sun9-11.u...1b8/dhmIRt3eZ8c.jpg",
                        "width": 605,
                        "height": 807
                    },
                    {
                        "type": "z",
                        "url": "https://sun9-37.u...1b9/3iavgJV9YWQ.jpg",
                        "width": 810,
                        "height": 1080
                    }
                ],
                "text": "",
                "date": 1531935090
            }
        ]
    }
}

the extract code :

        

json j = json::parse("your_file.json");

for (const auto& item : j["response"]["items"])
{
    int id = item["id"];
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值