【问题标题】:JSON File has square brackets instead of curly bracketsJSON文件有方括号而不是大括号
【发布时间】:2016-12-07 21:53:25
【问题描述】:

我有以下 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 中使用子输出。我目前的格式会有问题吗?

非常感谢,艾伦。

【问题讨论】:

  • 那是什么语言?它不是 Swift 或 Objective-C。那是Javascript吗?您应该将该信息添加到您的问题标题并添加适当的标签。
  • 是Django,我会在问题中添加它。

标签: python ios json django uitableview


【解决方案1】:

JSON 中的方括号表示一个数组。 example

您只是担心在 JSON 结果中返回方括号,还是无法使用 Json 结果?

*已编辑以修复链接描述

【讨论】:

  • 我还没有尝试使用结果,因为我想我会检查我是否已经做错了什么,我会阅读你的链接:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-05
  • 1970-01-01
  • 2015-06-29
  • 2016-07-17
  • 2014-10-16
  • 1970-01-01
相关资源
最近更新 更多