Skip to content

Instantly share code, notes, and snippets.

@roycrxtw
Last active March 17, 2017 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roycrxtw/b09b97fd8b12ef38903c2753faf0c8a3 to your computer and use it in GitHub Desktop.
Save roycrxtw/b09b97fd8b12ef38903c2753faf0c8a3 to your computer and use it in GitHub Desktop.
Convert json to html with a very simple html layout.
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