我有一个 JSON 如下:
{
"workloadId": "68cf9344-5a3c-4e4a-927c-c1c9b6e48ccc",
"elements": [
{
"name": "element1",
"uri": "vm/hpcloud/nova/large"
},
{
"name": "element2",
"uri": "vm/hpcloud/nova/small"
}
],
"workloadStatus": "none"
}
我需要按如下方式获取逗号分隔的字符串:element1,element2
当我尝试如下给出时,我得到了空字符串:
app.post('/pricingdetails', function(req, res) {
var workload = req.body;
var arr = new Array();
for(var index in workload.elements)
{
arr[index] = workload.elements[index].uri;
}
console.log(arr.join(","));
}