Ich habe folgendes Django Code:JSON-Datei hat eckige Klammern anstelle von geschweiften Klammern
def jsonLiveLeaderboard(request):
cursor = connection.cursor()
cursor.execute(
"""
select username as User, CAST(floor((count(Goals)/2)-(if(sum(Loss)>0,1,0))) as UNSIGNED) as Round, CAST(sum(Win) as UNSIGNED) as Wins, CAST(sum(Goals) as UNSIGNED) as Goals, CAST(sum(Loss) as UNSIGNED) as Losses from
(select u.username as username, s.campaignno as campaign, if(f.hometeamscore>f.awayteamscore,1,0) as Win, if(f.hometeamscore<f.awayteamscore,1,0) as Loss, f.hometeamscore as Goals from straightred_fixture f, straightred_userselection s, auth_user u where s.fixtureid = f.fixtureid and s.teamselectionid = f.hometeamid and s.user_id = u.id union all
select u.username as username, s.campaignno as campaign, if(f.awayteamscore>f.hometeamscore,1,0) as Win, if(f.awayteamscore<f.hometeamscore,1,0) as Loss, f.awayteamscore as Goals from straightred_fixture f, straightred_userselection s, auth_user u where s.fixtureid = f.fixtureid and s.teamselectionid = f.awayteamid and s.user_id = u.id) t
group by username, campaign
having Losses = 0
order by Round DESC, Wins DESC, Goals DESC
""")
json_data = json.dumps(cursor.fetchmany(size=5))
return HttpResponse(json_data, content_type='application/json')
Dieser Code erzeugt die folgende Ausgabe:
[["tingeyal", 3, 5, 16, 0], ["shanu", 2, 4, 12, 0], ["kevry", 2, 4, 12, 0], ["d_whoppa", 2, 4, 9, 0], ["kriste8403", 2, 4, 8, 0]]
wie bei zu sehen ist:
https://str8red.com/jsonLiveLeaderboard/
Meine Ergebnisse werden normalerweise in {Klammern und nicht [Klammern] zurückgegeben.
Mein Endspiel ist es, die Sohn-Ausgabe in einem iOS UITableView zu verwenden. Wird mein aktuelles Format ein Problem sein?
Vielen Dank, Alan.
Welche Sprache ist das? Es ist nicht Swift oder Objective-C. Ist das Javascript? Sie sollten diese Informationen zu Ihrem Fragentitel hinzufügen und das entsprechende Tag hinzufügen. –
Es ist Django, ich werde es zu der Frage hinzufügen. –