javascript - Can't get Data from json object -


i have script:

<script type="text/javascript">         function requestimg(username){                 $.ajax({                     url: '{% url "image" %}',                     data: {                       'username': username                     },                     datatype: 'json',                     success: function (data) {                         if (data) {                             //printing whole data                             console.log(data);                             //printing see                             console.log("name: ");                             //trying rint name                             console.log(data[0].nombre);                         }else {                              alert("may day");                         }                     }                 });         } 

i have problem reading properties in json object when print data this:

{     json: "[         {             "model": "polls.imagen",             "pk": 17,             "fields": {                 "n…"36",                 "imagen": "polls/static/pictures/dr.jpg"             }         }     ]" } 

and when print data have on code get:

uncaught typeerror: cannot read property 'nombre' of undefined 

i have tryied writing data.nombre undefined

i have tried console.log(data[0].fields); , data[0].model, data.model

important want clarify wont know why there 2 json objects im supposed 1 , if try put [1] instead of [0] same mistakes.

i've tried answers previous similar questions , didn't help.

you able access fields per

data.json[0].fields 

the response of url array, named json

additionally data.json returning string, convert json with

data.json = json.parse(data.json); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -