Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert table data into Json format in html

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to convert table table data into Json format". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to convert table table data into Json format in htmltable" can help you solve the problem.

Var keysArr = new Array ("key0", "key1", "key2")

Function TableToJson (tableid) {/ / tableid is the table name of the table you want to convert, which is a string, such as "example"

Var rows = document.getElementById (tableid) .rows.length; / / get the number of rows (including thead)

Var colums = document.getElementById (tableid). Rows [0] .cells.length; / / get the number of columns

Var json = "["

Var tdValue

For (var I = 1; I < rows; iTunes +) {/ / per line

Json + = "{"

For (var j = 0; j < colums; jacks +) {

TdName = keysArr [j]; / / key for Json data

Json + = "\"; / / add a double quotation mark

Json + = tdName

Json + = "\"

Json + = ":"

TdValue = document.getElementById (tableid). Rows [I]. Cells [j] [xss_clean]; / / the value of Json data

If (j = 1) {/ / the first column is in date format and needs to be added as follows according to json requirements

TdValue = "\ / Date (" + tdValue + ")\ /"

}

Json + = "\"

Json + = tdValue

Json + = "\"

Json + = ","

}

Json = json.substring (0, json.length-1)

Json + = "}"

Json + = ","

}

Json = json.substring (0, json.length-1)

Json + = "]"

Return json

}

This is the end of the introduction about "how to convert the table data in html to Json format". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report