我有以下Django代码:
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')此代码生成以下输出:
[["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]]可以在以下位置看到:
https://str8red.com/jsonLiveLeaderboard/
我的结果通常在{方括号中返回,而不是[方括号。
我的最终目的是在iOS UITableView中使用son输出。我现在的格式会是个问题吗?
非常感谢,艾伦。
发布于 2016-12-08 05:57:40
https://stackoverflow.com/questions/41028058
复制相似问题