在使用 Dropzone.js 插件后,我收到服务器的响应,我需要获取“thumbnail_url”但无法执行此操作。它是包含json对象的数组。
“[{”name“:”Lighthouse.jpg“,”url“: “/ your_uploads / multiuploader_file / 8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2 /”, “id”:“8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2”,“thumbnail_url”: “缩略图/ Lighthouse.8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2.jpg” “delete_type”:“POST”,“delete_url”: “/ your_uploads / multiuploader_delete / 8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2 /”, “size”:561276}]“
我尝试了很多方式,但没有任何效果,我尝试下面它工作,但我不能更改服务器代码,所以帮助我从上面的json数组中获取。
var obj={"name": "Lighthouse.jpg", "url": "/your_uploads/multiuploader_file/8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2/", "id": "8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2", "thumbnail_url": "thumbnails/Lighthouse.8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2.jpg", "delete_type": "POST", "delete_url": "/your_uploads/multiuploader_delete/8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2/", "size": 561276};
>>> obj.name
"Lighthouse.jpg"
答案 0 :(得分:1)
您在对象数组中的JSON。要访问第一个对象键,请使用jso[0].thumbnail_url
试试这个
$(document).ready(function () {
var jso = [{
"name": "Lighthouse.jpg",
"url": "/your_uploads/multiuploader_file/8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2/",
"id": "8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2",
"thumbnail_url": "thumbnails/Lighthouse.8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2.jpg",
"delete_type": "POST",
"delete_url": "/your_uploads/multiuploader_delete/8d1c455f5c49a9cfec8a3e880ff4d6904e2ce4a2/",
"size": 561276
}]
alert(jso[0].thumbnail_url)
});
答案 1 :(得分:0)
尝试以下解决方案
alert(obj[0].name);
alert(obj[0].thumbnail_url);
答案 2 :(得分:0)
在你的成功方法中试试这个:
$.each(data, function(i, item){
console.log(item.thumbnail_url);
});