2017-10-19 337 views
-3

我想從JSON輸出中提取一些屬性值,但我一直無法做到這一點,我需要將提取的每個值提供給一個函數,任何幫助表示讚賞!請在JSON下面找到,我需要在JavaScript中以字符串的形式提取文件名值。所以結果應該是2389063RX2_000003.tif, 2389063RX2_000004.tif,2389063RX2_000002.tif。 由於事先從json獲取屬性javascript

{ 
    "Items": [ 
    { 
     "filename": { 
     "S": "2389063RX2_000003.tif" 
     }, 
     "LastChecked": { 
     "S": "2013-10-16" 
     }, 
     "Checkdate": { 
     "S": "2017-10-16" 
     }, 
     "ContentType": { 
     "S": "image" 
     }, 
     "UID": { 
     "S": "2389063RX2_000003" 
     }, 
     "md5": { 
     "S": "e2670dc6daded994066942004c1f6806" 
     } 
    }, 
    { 
     "filename": { 
     "S": "2389063RX2_000004.tif" 
     }, 
     "LastChecked": { 
     "S": "2015-10-16" 
     }, 
     "Checkdate": { 
     "S": "2017-10-16" 
     }, 
     "ContentType": { 
     "S": "image" 
     }, 
     "UID": { 
     "S": "2389063RX2_000004" 
     }, 
     "md5": { 
     "S": "\nd1979275e0add942356b5b472fbadc73" 
     } 
    }, 
    { 
     "filename": { 
     "S": "2389063RX2_000002.tif" 
     }, 
     "LastChecked": { 
     "S": "2016-10-16" 
     }, 
     "Checkdate": { 
     "S": "2017-10-16" 
     }, 
     "ContentType": { 
     "S": "image" 
     }, 
     "UID": { 
     "S": "2389063RX2_000002" 
     }, 
     "md5": { 
     "S": "a48974a06a11d8548bedfcac7b5624ec" 
     } 
    } 
    ], 
    "Count": 3, 
    "ScannedCount": 3 
} 
+1

'object.items.map(OBJ => obj.filename)' – Rajesh

回答

0

這是你需要什麼,我猜。迭代這個json對象並僅捕獲文件名。

ES6

let arrayOfFilenames = jsonVariable.items.map((e) => e.filename); 

ES5

var arrayOfFilenames = jsonVariable.items.map(function (e) { 
    return e.filename; 
});