2015-11-02 77 views
-1

是的,我已經知道如何對象添加到JSON(的NodeJS)

json.newvalue = 'newvalue' 

但我不會找那個...... 我有一個空的JSON

plugins = {}; 

現在我需要5個項目添加到它,例如:

{"name":"test"} 
{"name":"test2"} 

我尋找的是這樣的:plugins.add({"name":"test"})

回答

0

首先,json是一個對象的字符串表示形式,你在代碼中擁有的是一個對象。但是,看起來你不需要JavaScript對象,而是一個數組。

var plugins = []; 
plugins.push({"name":"test"}); 
plugins.push({"name":"test2"}); 

插件現在將

[ 
    {"name", "test"}, 
    {"name", "test2"} 
] 
+0

這工作過,那麼我可以JSON.stringify(); – Community