How to read/load a JSON file in Typescript -
i quite new typescript , trying read simple json file typescript. have googled , tried need simple code lines read local json file nummeric array variable. json file [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 16.4, 194.1, 95.6, 54.4].
if can me out on this, grateful
regards gf
standard javascript -
var json = "[29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 16.4, 194.1, 95.6, 54.4]"; var arr = json.parse(json);
(edit)
just noticed "local file" bit - if mean @ compile time need prefix json (in file) variable name nothing else needs doing - quite literally simple window.json = ...
works - there's no need quotes etc. if it's @ runtime needs loaded either via ajax, or - again - via prefixing variable name , adding file in <script type="text/javascript" src="file.json"></script>
tag.
Comments
Post a Comment