美文网首页
拼接json

拼接json

作者: 阿鲁提尔 | 来源:发表于2018-10-09 13:20 被阅读0次
/*提交json*/
    var jsonCardname, jsonTestswitch, jsonTesteditor = [], jsonTestdatestart, jsonTestdateend,
        json = {"cardname": "","testswitch": "", "testobjectselect": "", "testdatestart": "", "testdateend": "", "testeditor": ""};

    $("#submit").on("click",function(){
        //提交获取最新json
        jsonCardname = $("#activeText").val();
        jsonTestdatestart = $(".testDateStart").val();
        jsonTestdateend = $(".testDateEnd").val();

        
        jsonTestswitch = true;
        jsonTesteditor = [];
        $('.addConBox').each(function(){
            var needJson = {"type": "", "value": ""};
            if($(this).find('textarea').length){
                needJson.type = "2";
                needJson.value = $(this).find('textarea').val();
                jsonTesteditor.push(needJson);
            }
            else if($(this).find('img').length){
                needJson.type = "1";
                needJson.value = $(this).find('img').attr('src');
                jsonTesteditor.push(needJson);
            };
        });

        //最新json数组
        json.cardname = jsonCardname;
        json.testswitch = jsonTestswitch;
        json.testeditor = jsonTesteditor;
        json.testdatestart = jsonTestdatestart;
        json.testdateend = jsonTestdateend;
        
        //提交最新json
        console.log(JSON.stringify(json));
    });
//拼装的结果
{
  "cardname":"哈哈好",
  "testswitch":true,
  "testobjectselect":"",
  "testdatestart":"2018年10月09日 10:00:00",
  "testdateend":"2018年10月09日 10:00:00",
  "testeditor":[
      {"type":"2","value":"大山东"},
      {"type":"1","value":"blob:null/281ea23c-3b7e-4b76-bd3b-d936d24b34bc"}
  ]
}

相关文章

网友评论

      本文标题:拼接json

      本文链接:https://www.haomeiwen.com/subject/vomeaftx.html