Reputation: 6555
I;m trying to get the value 'content'
from my json data
This is the data:
[{"pk": 2, "model": "template", "fields": {"content": "message", "status": "Draft", "user": 16, "name": "test", "created": "2013-05-19T20:59:04Z"}}]
This is what I have tried:
$.getJSON('/sms/fetch/' + id, function (data) {
$('#id_content').val($('#id_content').val() + data.fields.content);
})
but this does not seem to get the value, the value is within the call as shown above.
Upvotes: 0
Views: 52
Reputation: 165951
Your data
appears to be an array of objects, so you need to access it by index:
console.log(data[0].fields.content); // "message"
Upvotes: 2