Reputation: 11639
Sorry for novice question, i am a beginner in JSON
.
I have the following json:
{
"destination_addresses" : [ "San Francisco, Californie, États-Unis", "Victoria, BC, Canada" ],
"origin_addresses" : [ "Vancouver, BC, Canada", "Seattle, Washington, États-Unis" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "1 707 km",
"value" : 1707145
},
"duration" : {
"text" : "3 jours 19 heures",
"value" : 327471
},
"status" : "OK"
},
]
},
],
"status" : "OK"
}
and i am going to get duration
value.
i used this line
duration = json["rows"][0]["elements"]["duration"]["text"]
but i am facing with this erorr
no implicit conversion of String into Integer (TypeError)
Upvotes: 0
Views: 496
Reputation: 66263
Looking at the example JSON, elements
is an array:
"elements" : [...
so needs to be indexed numerically e.g.
duration = json["rows"][0]["elements"][0]["duration"]["text"]
currently the string "duration"
is being used to index into the elements
array leading to the error you're seeing.
Upvotes: 2