AlhasanIQ
AlhasanIQ

Reputation: 183

Selecting json data in JQuery

i have an ajax form and the response data is this json

[{"runtime":"142 min" , "title":"blabla"}]

but when i see it from chrome developer tools it is like this

[Object]
0: Object
runtime: "142 min"
title: "blabla"
__proto__: Object
length: 1
__proto__: Array[0]

if i want to set one of the keys to a var what should i do

i tried var x = data.runtime ; but it isnt working

i tried var x = data.0.runtime ; and it makes a syntax error

Upvotes: 0

Views: 41

Answers (1)

Avner Shahar-Kashtan
Avner Shahar-Kashtan

Reputation: 14700

Note the square brackets around your JSON data - it's not an object, but an array, containing one value - your object.

To access that object, access the first value in the array: data[0].runtime.

Upvotes: 5

Related Questions