Last active
March 17, 2017 16:58
-
-
Save roycrxtw/b09b97fd8b12ef38903c2753faf0c8a3 to your computer and use it in GitHub Desktop.
Convert json to html with a very simple html layout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
// load json file | |
var obj = fs.readFileSync('data.json', 'utf8'); | |
var htmlStart = '<html><body>'; //因示範用途,故簡化html結構 | |
var htmlEnd = '</body></html>'; | |
var htmlContent = ''; | |
for(var i in obj){ | |
htmlContent += '<hr>' | |
+ '<h3>' + obj[i].name + '</h3>' | |
+ '<ul><li>日期: ' + obj[i].date + '</li>' | |
+ '<li>均溫: ' + obj[i].avg + '</li>' | |
+ '<li>最高溫: ' + obj[i].max + '</li>' | |
+ '<li>最低溫: ' + obj[i].min + '</li></ul>' | |
} | |
var html = htmlStart + htmlContent + htmlEnd; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment