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": "teste4@hotmail.com", "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)
Advertisement
Answer
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)