0

I'm trying to get the values ​​from json estimatedDeliveryDate and amount but I have found errors and difficulties to get these values, I tried several ways but none managed to extract the result, if anyone has any tips on how I can do this thank you, follow the code below in javascript plus json for the extraction

var json = {
    "links": [
        {
            "rel": "self",
            "href": "https://www.usereserva.com/ccstoreui/v1/shippingMethods"
        }
    ],
    "items": [
        {
            "shippingGroupId": "0",
            "shippingAddress": {
                "computedState": [
                    "RS"
                ],
                "lastName": " asdas",
                "country": "BR",
                "numero": "",
                "city": "Erechim",
                "prefix": "",
                "dynamicProperties": [

                ],
                "postalCode": "99711268",
                "jobTitle": "",
                "companyName": "",
                "county": "",
                "predefinedAddressTypes": [

                ],
                "isDefaultAddress": false,
                "suffix": "",
                "type": "",
                "selectedCountry": "BR",
                "computedCountry": [
                    "BR"
                ],
                "selectedAddressTypes": [

                ],
                "complemento": "",
                "populateShippingMethods": true,
                "alias": "",
                "addressDescriptionComputed": "Rua Ernesto Pagnoncelli, Koller, Erechim - RS",
                "state": "RS",
                "isDefaultShippingAddress": false,
                "email": "[email protected]",
                "selectedState": "RS",
                "state_ISOCode": "BR-RS",
                "isDefaultBillingAddress": false,
                "types": [

                ],
                "address3": "Koller",
                "address2": "",
                "address1": "Rua Ernesto Pagnoncelli",
                "addressType": [

                ],
                "defaultCountryCode": "BR",
                "isTypeModified": false,
                "firstName": "teste",
                "phoneNumber": "(54) 984354020",
                "computedDefaultShipping": false,
                "computedDefaultBilling": false,
                "repositoryId": "",
                "recipient": "teste asdas",
                "faxNumber": "",
                "computedAddressType": [

                ],
                "middleName": "",
                "referencia": ""
            },
            "items": [
                {
                    "commerceItemId": "ci17672126437481",
                    "quantity": 1,
                    "productId": "0053394",
                    "catRefId": "005339401402"
                }
            ],
            "shippingMethods": [
                {
                    "shippingCalculator": "priceRange",
                    "eligibleForProductWithSurcharges": false,
                    "isExternallyPriced": false,
                    "ranges": [
                        {
                            "amount": 0.0,
                            "high": null,
                            "low": 0.0,
                            "repositoryId": "100001"
                        }
                    ],
                    "associatedPriceListGroups": [
                        {
                            "repositoryId": "real"
                        }
                    ],
                    "displayName": "Retire em Loja",
                    "description": "Retire em Loja",
                    "allSites": true,
                    "sites": [

                    ],
                    "taxCode": null,
                    "type": 0,
                    "shippingGroupType": "hardgoodShippingGroup",
                    "enabled": true,
                    "displaySequence": 0,
                    "repositoryId": "100001",
                    "excludedCategoriesShippingCharge": [

                    ],
                    "isFallback": false,
                    "id": "100001",
                    "shipToLocations": [
                        {
                            "repositoryId": "100001"
                        }
                    ],
                    "excludedCategories": [

                    ]
                },
                {
                    "shippingCalculator": "external",
                    "eligibleForProductWithSurcharges": false,
                    "estimatedDeliveryDateGuaranteed": false,
                    "internationalDutiesTaxesFees": "0",
                    "ranges": [
                        {
                            "amount": 19.87,
                            "high": 1.7976931348623157E308,
                            "low": 0
                        }
                    ],
                    "displayName": "Transporte Padrão",
                    "taxCode": "GT987",
                    "shippingGroupType": "hardgoodShippingGroup",
                    "estimatedDeliveryDate": "2020-08-21T17:21:05Z",
                    "enabled": true,
                    "deliveryDays": 12,
                    "repositoryId": "Transporte Padrão",
                    "carrierId": "ON"
                }
            ]
        }
    ]
}

var deliveryDate = json["items"];
var deliveryPrice = json.items;
console.log(JSON.stringify(deliveryDate));
console.log(JSON.stringify(deliveryPrice));

// I NEED GET THAT JSON
//console.log(json.items[1].shippingMethods[2].estimatedDeliveryDate)
//console.log( json.items[1].shippingMethods[2].ranges[1].amount)
4
  • That is an object literal, not JSON. Commented Aug 5, 2020 at 21:14
  • How can I access and process nested objects, arrays or JSON? Commented Aug 5, 2020 at 21:15
  • 2
    I have found errors and difficulties you need to be way more specific. What errors? What difficulties? Commented Aug 5, 2020 at 21:16
  • json.items[0].shippingMethods[1].estimatedDeliveryDate, but you might want to do some traversing here, it's built of arrays.. Commented Aug 5, 2020 at 21:18

1 Answer 1

1

Arrays are zero-indexed, which means that index 0 is the first element, not 1.

console.log(json.items[0].shippingMethods[1].estimatedDeliveryDate)
console.log(json.items[0].shippingMethods[1].ranges[0].amount)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.