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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -