【问题标题】:Getting [[Object]] when saving JSON保存 JSON 时获取 [[Object]]
【发布时间】:2014-08-16 16:31:14
【问题描述】:

我正在尝试用“某处”保存一个 json。

此功能不完整,但足以说明问题:

function testJSON(products) { 
var productsPromises = products.map(function(product) { 
    var title = product['Title']; 
    var stock = product['Stock']; 
    var price = product['Price']; 
    if (stock == "Disponible") { 
        stock = true; 
    } else { 
        stock = false; 
    } 
    var toPush = [{Stock: stock, Price: price}]; 
    var results = {Title: title, Results: toPush}; 
    db.connect('./xxxxx/results.json'); 
    var find = db.find('Productos', {Title: title}); 
    console.log(find); 


}); 
return Promise.all(productsPromises); 

}

返回:

[ { Title: 'Grabador de voz ISD1932', 
Results: [ [Object] ], 
id: 'f4099bff-fc55-4697-b712-d84343931818' } ] 
[ { Title: 'Arduino SD Card Shield', 
Results: [ [Object] ], 
id: '75c79411-a905-41b3-9578-bb7072139a4d' } ] 
[ { Title: 'Placa prototipo con zócalo para microSD Transflash', 
Results: [ [Object] ], 
id: 'af21962a-197e-43db-aba2-779be95357f2' } ] 
[ { Title: 'Frontal para LCD 32PTU (Negro)', 
Results: [ [Object] ], 
id: '29d1e6cd-b549-44ad-87af-e4a4a056a609' } ] 

我以同样的方式保存它,但使用

 db.save('Productos', results); //instead of db.find(... 

为什么我得到的是 [[Object]] 而不是数据?我怎样才能解决这个问题?

【问题讨论】:

    标签: javascript json save


    【解决方案1】:

    我想db.save('Productos', JSON.stringify(results)); 应该这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      • 2018-01-03
      • 2014-01-15
      • 2023-03-06
      • 1970-01-01
      • 2016-01-13
      • 2018-09-16
      相关资源
      最近更新 更多