首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSON文件具有方括号而不是花括号

问JSON文件具有方括号而不是花括号
EN

Stack Overflow用户
提问于 2016-12-08 05:53:26
回答 1查看 774关注 0票数 0

我有以下Django代码:

代码语言:javascript
复制
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')

此代码生成以下输出:

代码语言:javascript
复制
[["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输出。我现在的格式会是个问题吗?

非常感谢,艾伦。

EN

回答 1

Stack Overflow用户

发布于 2016-12-08 05:57:40

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

您只是关心如何在JSON结果中恢复方括号,还是无法使用Json结果?

*已编辑以修复链接描述

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41028058

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档