JavaScript 拼接JSON

<script language="javascript" type="text/javascript">
        var json="";
        $(document).ready(function () {
            $("#Button1").bind("click", function () {
                $.ajax({
                    type: "post",
                    url: "GiftBox_RePrint.aspx?Oper=load_templateslist&key=" + Math.round(),
                    dataType: "text",
                    cache: false,
                    success: function (data) {
                        var arr_temp_list = new Array(); //返回的全部数据

                        var arr_temp_id = new Array(); //保存所有的模板ID
                        var arr_temp_name = new Array(); //保存所有的模板名称
                        arr_temp_list = data.split(","); //根据逗号拆分,结果为ID:Name                        
                        json += "[";
                        for (i = 0; i < arr_temp_list.length; i++) {
                            arr_temp_id.push(arr_temp_list[i].substring(0, arr_temp_list[i].indexOf(":")));
                            arr_temp_name.push(arr_temp_list[i].substring(arr_temp_list[i].indexOf(":") + 1, 3000));

                            if (i > 0) {
                                json += ",";
                            }
                            json += "{\"LOT_ID\":\"" + arr_temp_id[i].toString() + "\",\"LOT_NAME\":\"" + escape( arr_temp_name[i].toString()) + "\"}";
                        }
                        json += "]";
                        $("#cmbTempList").combobox("loadData", json);

                    }
                });               

            });

        });       
    </script>

你可能感兴趣的:(JavaScript 拼接JSON)