NATIVE with node.js API 从数据库中获取数据,我以嵌套的 JSON 字符串格式获取数据,主要是“file_Name”:“3.jpg,2.jpg,1.jpg”,但我想要“file_Name”:[ “3.jpg”、“2.jpg”、“1.jpg”] 嵌套 JSON 数组格式,我尝试使用 for 循环和推送,通过使用 for 循环我从 rows_Data 获取数组但我不知道 w将其推送到 rows_Data。
如果有人知道任何替代解决方案,请检查代码,请帮助我。,
rows_Data = [{
"id": 4,
"user_id": 2,
"description": " Hi How are you ",
"post_type": 0,
"created_date": "2019-01-28T19:30:49.000Z",
"name": "sankar ",
"mobile": 9985849966,
"picture_url": "2.jpg",
"post_id": 4,
"saved_name": "9.jpg",
"file_Name": "10.jpg,9.jpg"
}, {
"id": 3,
"user_id": 1,
"description": " Working a Fine ",
"post_type": 0,
"created_date": "2019-01-25T18:40:41.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 3,
"saved_name": "8.jpg",
"file_Name": "7.jpg,8.jpg"
}, {
"id": 2,
"user_id": 1,
"description": " Hello hi",
"post_type": 1,
"created_date": "2019-01-21T12:51:16.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 2,
"saved_name": "4.jpg",
"file_Name": "6.jpg,5.jpg,4.jpg"
}, {
"id": 1,
"user_id": 1,
"description": " Hi How are you ",
"post_type": 0,
"created_date": "2019-01-21T12:50:51.000Z",
"name": "Sivasankar",
"mobile": 9985849955,
"picture_url": "5.jpg",
"post_id": 1,
"saved_name": "1.jpg",
"file_Name": "3.jpg,2.jpg,1.jpg"
}]
console.log(rows_Data);
var copy= []; ;
var res_ = {};
var file_Name ={};
var result = {};
for (let i = 0; i < rows_Data.length; i++) {
copy.push(rows_Data[i].file_Name);
for (let j = 0; j < copy.length; j++) {
res_[j] = copy[j].split(",");
for (let k = 0; k < res_.length; j++) {
rows_Data[k].file_Name.push(res_[k]);
}
}
}
console.log(copy);
console.log( res_);
console.log(rows_Data)
白衣染霜花
陪伴而非守候
相关分类