javascript - Load JSON data and display in various divs -
i'm new json, , rusty on javascript, has been bit of struggle. i'm trying load json data file, , split div containers. i'm being asked create shell page load json data , populate page based on markup , data in json file can include of: links, text, or embed code. results on here extremely mixed methods used either not explained, or deprecated.
a json structure came was:
{"week1":[ {"desc":"description", "link":"linkhere", "mda":"mediahere"} ]}
my concern chiefly, loading correctly without fluff local file , displaying it. i'm looking fresh perspective on , coding help.
here example, week create div, , array inside week, create elements inside div
var myjson = {"week1":[ {"desc":"description", "link":"linkhere", "mda":"mediahere"}, {"desc":"description2", "link":"linkhere2", "mda":"mediahere2"} ], "week2":[ {"desc":"description3", "link":"linkhere3", "mda":"mediahere3"}, {"desc":"description3", "link":"linkhere3", "mda":"mediahere3"} ]}; $.each(myjson, function(i, week) { $('body').append('<div class="' + + '">' + + '<br></div>'); $.each(week, function(j, val) { var text = '<ul><li>' + val.desc + '</li><li>' + val.link + '</li><li>' + val.mda + '</li></ul>'; $('div[class="' + + '"]').append(text); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <body> <body>