JSON中的地址数

number of addresses in JSON?

本文关键字:地址 JSON      更新时间:2023-09-26

我有以下JSON(我验证并验证是正确的),我试图获得地址的数量。当我输入

var location = req.body;

我得到

{ AddressValidateRequest:
   { '-USERID': 'xxxxxxxxxxx',
     Address: [ [Object], [Object], [Object] ] } }

我如何得到地址的数量?

{
    "AddressValidateRequest": {
        "-USERID": "xxxxxxxxxxx",
        "Address": [
            {
                "-ID": "0",
                "FirmName": "firmname",
                "Address1": "address1here",
                "Address2": "13 infinite loop",
                "City": "new york",
                "State": "NY",
                "Zip5": "zip5here",
                "Zip4": "zip4here"
            },
            {
                "-ID": "1",
                "FirmName": "firmhere",
                "Address1": "address1here",
                "Address2": "1 Smith Ct ",
                "City": "San Predo",
                "State": "CA",
                "Zip5": "ziphere",
                "Zip4": "ziphere1"
            },
            {
                "-ID": "1",
                "FirmName": "firmhere",
                "Address1": "address1here",
                "Address2": "12 John Rd ",
                "City": "Newark",
                "State": "PA",
                "Zip5": "ziphere",
                "Zip4": "ziphere1"
            }
        ]
    }
}

应该可以了

req.body.AddressValidateRequest.Address.length

获取一个特定的地址(例如,第一个)

req.body.AddressValidateRequest.Address[0]

获取地址的字段

req.body.AddressValidateRequest.Address[0].City
// "New York"