0

I have an array of objects coming in as part of a JSON response, as shown below. I need to extract one of the "value" string items. The problem, however, is that some of the "value" items are strings, some are arrays of strings and some are objects themselves. Any advice on how to proceed with this?

This is the portion of that JSON that I am talking about (I need to extract the value for employee number):

"meta_data": [
        {
            "id": 20,
            "key": "wc_last_active",
            "value": "1591574400"
        },
        {
            "id": 21,
            "key": "jetpack_tracks_anon_id",
            "value": "jetpack:XPs4qwPuwtU9/37vf635CIal"
        },
        {
            "id": 22,
            "key": "wpsl_disable_key_warning",
            "value": "true"
        },
        {
            "id": 26,
            "key": "nav_menu_recently_edited",
            "value": "52"
        },
        {
            "id": 27,
            "key": "managenav-menuscolumnshidden",
            "value": [
                "link-target",
                "css-classes",
                "xfn",
                "description",
                "title-attribute"
            ]
        },
        {
            "id": 40,
            "key": "dismissed_no_shipping_methods_notice",
            "value": "1"
        },
        {
            "id": 41,
            "key": "dismissed_no_secure_connection_notice",
            "value": "1"
        },
        {
            "id": 108,
            "key": "iconic-register-text",
            "value": "54321"
        },
        {
            "id": 111,
            "key": "employee_number",
            "value": "5432145623"
        },
        {
            "id": 199,
            "key": "tgmpa_dismissed_notice_tgmpa",
            "value": "1"
        },
        {
            "id": 207,
            "key": "community-events-location",
            "value": {
                "ip": "xxxxxxxxxxxx"
            }
        },
        {
            "id": 295,
            "key": "mobiconnector-avatar",
            "value": ""
        },
        {
            "id": 367,
            "key": "shipping_method",
            "value": ""
        },
        {
            "id": 368,
            "key": "shipping_email",
            "value": "xxxxxxxxxxx"
        },
        {
            "id": 369,
            "key": "shipping_phone",
            "value": "xxxxxxxxxx"
        },
        {
            "id": 579,
            "key": "dismissed_update_notice",
            "value": "1"
        },
        {
            "id": 800,
            "key": "supsystic-tables-tutorial_was_showed",
            "value": "1"
        },
        {
            "id": 801,
            "key": "dismissed_template_files_notice",
            "value": "1"
        },
        {
            "id": 804,
            "key": "managetablepress_listcolumnshidden",
            "value": [
                "table_last_modified_by"
            ]
        },
        {
            "id": 1849,
            "key": "edit_shop_order_per_page",
            "value": "100"
        }
    ]
  • Can you provide some code that gives context about how you plan to use this response? – yohannist Jun 11 '20 at 11:04
  • ```objArray.FirstOrDefault(a => a.key == "employee_number")?.value``` should give you what you need with objArray being the json array. – yohannist Jun 11 '20 at 11:09

0 Answers0