JSON忽略空格后的文本(空格)

时间:2018-03-09 14:01:20

标签: javascript jquery json

我有一个这种格式的JSON

   var json = [{
            "html": "Brand 5", //testing this failed
            "col": 1,
            "row": 1,
            "size_y": 2,
            "size_x": 3
        }, {
            "html": "Brand 5", 
            "col": 4,
            "row": 1,
            "size_y": 2,
            "size_x": 2
        },

        {
            "html": "Brand 5",
            "col": 6,
            "row": 1,
            "size_y": 2,
            "size_x": 2
        },


        {
            "html": "Brand 5",
            "col": 1,
            "row": 3,
            "size_y": 2,
            "size_x": 3
        }, {
            "html": "Brand 5",
            "col": 4,
            "row": 3,
            "size_y": 2,
            "size_x": 2
        },

        {
            "html": "Brand 5",
            "col": 6,
            "row": 3,
            "size_y": 2,
            "size_x": 2
        }

        ];

我试着借助这段代码把它放在我的网格上

for(var index=0;index<json.length;index++) {
        gridster.add_widget('<li class="new" ><button class="delete-button" style="float: right;">-</button><input type="text" size="3" value=' +json[index].html+ '/></li>',json[index].size_x,json[index].size_y,json[index].col,json[index].row);

};

但问题是,空格后的文本会被忽略,原因可能是

我只在文本框中获得Brand而不是Brand 5

1 个答案:

答案 0 :(得分:2)

你忘了2次:&#34;

必须是:

....value="' +json[index].html+ '"/>....
相关问题