日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

把html转换为json数据,HTML转成JSON数据

發布時間:2023/12/20 HTML 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 把html转换为json数据,HTML转成JSON数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

例如以下HTML

01010004一次性注射器10ml

要轉換成 {"ID":"01010004","Name":"一次性注射器","Specification":"10ml"} 進行存儲

有什么插件或者思路

補充如下:

HTML結構:

且或且
  • 沈陽

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

  • 重慶

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

  • 西安

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

  • 廣州

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

  • 深圳

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

  • 長春

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

  • 上海

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

    屬于

    不屬于

    包含

    不包含

    為空

    非空

    開頭是

    結尾是

JS方法如下:(采用jQuery)

function getFilterTableData(tableID) {

var operatorMap = {

1: 'AND',

2: 'OR'

};

var conditionAndRangeMap = {

condition: function($obj) {

return $obj.children('select').val()

},

pickRange: function($obj) {

return {

val: $obj.children('select').val(),

mode: 'select'

}

},

editRange: function($obj) {

return {

val: $obj.children('input').val(),

mode: 'input'

}

},

nullRange: function($obj) {

return

}

};

var c = '.tableStyle-2-container',

h = '.tableStyle-2-operator',

b = '.tableStyle-2-content',

l = '.tableStyle-2-content-list',

li = '.tableStyle-2-content-list-unitRow',

label = '.unitRow-label';

var result = {};

var $start = $(tableID).children();

var looper = function($c, data) {

var $unitH = $c.children(h), //操作符

$unitB = $c.children(b), //內容

$unitB_children = $unitB.children(); //內容子節點

//如果有操作符

if($unitH.length) {

data.type = operatorMap[$unitH.attr('operator')];

}

//存儲子節點信息

data.children = [];

//如果內容有子節點

if($unitB_children.length) {

var $unitL = $unitB.children(l); //內容 - 列表

var $unitC = $unitB.children(c); //內容 - 容器

if($unitL.length) {

var children = [];

var $lis = $unitL.children(li);

for(var i = 0, length = $lis.length; i < length; i++) {

var $label = $lis.eq(i).children(label);

var $condition = $label.next();

var $range = $condition.next();

var unitRowData = $.extend({

col: $label.text()

}, {

rel: conditionAndRangeMap[$condition.attr('class').split('-')[1]]($condition),

}, conditionAndRangeMap[$range.attr('class').split('-')[1]]($range));

children.push(unitRowData);

}

data.children.push({

children: children

});

}

if($unitC.length) {

data.children.unshift({});

looper($unitC, data.children[0]);

}

}

}

looper($start, result);

return result

}

var resultData = getFilterTableData('#businessData-filter-table');

console.log(JSON.stringify(resultData));

總結

以上是生活随笔為你收集整理的把html转换为json数据,HTML转成JSON数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。