Skip to content

Commit 0a6c2e0

Browse files
committed
fixed json parsing
1 parent f58c647 commit 0a6c2e0

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
0 Bytes
Binary file not shown.

newsapp/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def map(request):
9393
del state_name_mapping['tt']
9494
x_ = requests.get('https://api.covid19india.org/state_district_wise.json').json()
9595
x_ = json.dumps(x_)
96+
# print(type(x_))
9697

9798
return render(request, 'newsapp/map.html', context={"statewise":json.dumps(a),"confirmed":json.dumps(confirmed),"recovered":json.dumps(recovered),"deceased":json.dumps(deceased),"codes":json.dumps(state_name_mapping), "code_map":state_name_mapping, "table":x_})
9899

templates/newsapp/map.html

+12-1
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,15 @@ <h2> Spread Trends</h2>
213213
</div>
214214
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
215215
<script>
216-
var table = JSON.parse(`{{ table|safe }}`);
216+
function httpGet(theUrl) {
217+
var xmlHttp = new XMLHttpRequest();
218+
xmlHttp.open("GET", theUrl, false); // false for synchronous request
219+
xmlHttp.send(null);
220+
return xmlHttp.responseText;
221+
}
217222
var state_codes = JSON.parse(`{{ codes|safe }}`);
223+
var table = JSON.parse(httpGet('https://api.covid19india.org/state_district_wise.json'));
224+
alert(table);
218225
var confirmed = JSON.parse(`{{ confirmed|safe }}`);
219226
var recovered = JSON.parse(`{{ recovered|safe }}`);
220227
var deceased = JSON.parse(`{{ deceased|safe }}`);
@@ -225,8 +232,12 @@ <h2> Spread Trends</h2>
225232
dec = 0,
226233
act = 0,
227234
rec = 0;
235+
// alert(typeof table);
236+
// table = JSON.parse(table);
237+
228238
for (var i in table) {
229239
// alert(i)
240+
230241
for (j in table[i]["districtData"]) {
231242
// alert(j);
232243
act += table[i]["districtData"][j]["active"];

0 commit comments

Comments
 (0)