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
JavaScript
x
160
160
1
var json = {
2
"links": [
3
{
4
"rel": "self",
5
"href": "https://www.usereserva.com/ccstoreui/v1/shippingMethods"
6
}
7
],
8
"items": [
9
{
10
"shippingGroupId": "0",
11
"shippingAddress": {
12
"computedState": [
13
"RS"
14
],
15
"lastName": " asdas",
16
"country": "BR",
17
"numero": "",
18
"city": "Erechim",
19
"prefix": "",
20
"dynamicProperties": [
21
22
],
23
"postalCode": "99711268",
24
"jobTitle": "",
25
"companyName": "",
26
"county": "",
27
"predefinedAddressTypes": [
28
29
],
30
"isDefaultAddress": false,
31
"suffix": "",
32
"type": "",
33
"selectedCountry": "BR",
34
"computedCountry": [
35
"BR"
36
],
37
"selectedAddressTypes": [
38
39
],
40
"complemento": "",
41
"populateShippingMethods": true,
42
"alias": "",
43
"addressDescriptionComputed": "Rua Ernesto Pagnoncelli, Koller, Erechim - RS",
44
"state": "RS",
45
"isDefaultShippingAddress": false,
46
"email": "teste4@hotmail.com",
47
"selectedState": "RS",
48
"state_ISOCode": "BR-RS",
49
"isDefaultBillingAddress": false,
50
"types": [
51
52
],
53
"address3": "Koller",
54
"address2": "",
55
"address1": "Rua Ernesto Pagnoncelli",
56
"addressType": [
57
58
],
59
"defaultCountryCode": "BR",
60
"isTypeModified": false,
61
"firstName": "teste",
62
"phoneNumber": "(54) 984354020",
63
"computedDefaultShipping": false,
64
"computedDefaultBilling": false,
65
"repositoryId": "",
66
"recipient": "teste asdas",
67
"faxNumber": "",
68
"computedAddressType": [
69
70
],
71
"middleName": "",
72
"referencia": ""
73
},
74
"items": [
75
{
76
"commerceItemId": "ci17672126437481",
77
"quantity": 1,
78
"productId": "0053394",
79
"catRefId": "005339401402"
80
}
81
],
82
"shippingMethods": [
83
{
84
"shippingCalculator": "priceRange",
85
"eligibleForProductWithSurcharges": false,
86
"isExternallyPriced": false,
87
"ranges": [
88
{
89
"amount": 0.0,
90
"high": null,
91
"low": 0.0,
92
"repositoryId": "100001"
93
}
94
],
95
"associatedPriceListGroups": [
96
{
97
"repositoryId": "real"
98
}
99
],
100
"displayName": "Retire em Loja",
101
"description": "Retire em Loja",
102
"allSites": true,
103
"sites": [
104
105
],
106
"taxCode": null,
107
"type": 0,
108
"shippingGroupType": "hardgoodShippingGroup",
109
"enabled": true,
110
"displaySequence": 0,
111
"repositoryId": "100001",
112
"excludedCategoriesShippingCharge": [
113
114
],
115
"isFallback": false,
116
"id": "100001",
117
"shipToLocations": [
118
{
119
"repositoryId": "100001"
120
}
121
],
122
"excludedCategories": [
123
124
]
125
},
126
{
127
"shippingCalculator": "external",
128
"eligibleForProductWithSurcharges": false,
129
"estimatedDeliveryDateGuaranteed": false,
130
"internationalDutiesTaxesFees": "0",
131
"ranges": [
132
{
133
"amount": 19.87,
134
"high": 1.7976931348623157E308,
135
"low": 0
136
}
137
],
138
"displayName": "Transporte Padrão",
139
"taxCode": "GT987",
140
"shippingGroupType": "hardgoodShippingGroup",
141
"estimatedDeliveryDate": "2020-08-21T17:21:05Z",
142
"enabled": true,
143
"deliveryDays": 12,
144
"repositoryId": "Transporte Padrão",
145
"carrierId": "ON"
146
}
147
]
148
}
149
]
150
}
151
152
var deliveryDate = json["items"];
153
var deliveryPrice = json.items;
154
console.log(JSON.stringify(deliveryDate));
155
console.log(JSON.stringify(deliveryPrice));
156
157
// I NEED GET THAT JSON
158
//console.log(json.items[1].shippingMethods[2].estimatedDeliveryDate)
159
//console.log( json.items[1].shippingMethods[2].ranges[1].amount)
160
Advertisement
Answer
Arrays are zero-indexed, which means that index 0
is the first element, not 1
.
JavaScript
1
3
1
console.log(json.items[0].shippingMethods[1].estimatedDeliveryDate)
2
console.log(json.items[0].shippingMethods[1].ranges[0].amount)
3