【问题标题】:sqlite table for json androidjson android的sqlite表
【发布时间】:2016-09-07 10:46:19
【问题描述】:

我有一个问题,因为我不知道该怎么做。我的项目展示了篮球技巧。它有这样的层次组合:主要类别,练习ListView,下一个是细节。

现在我需要为这个 Json 创建一个 sqlite 数据库。我需要为下面的 Json 创建 2 个表还是只使用一个就足够了?另外,有谁知道在哪里可以找到我的问题的类似示例?

{
    "Basketball":[
    {
        "ids":1,
            "category":"Shooting",
            "catThumb":"http://cbssports.com/images/visual/whatshot/USATSI_8176966.jpg",
            "exercises":[
        {
            "id":1,
                "name":"Shooting drills",
                "thumb":
            "http://app.akharinkhabar.ir/AndroidOnlineNewsImage.aspx?id=7531955",
                    "description":"good clips of Steph Curry's real summer workout..",
                "video":"GkcHK11xpLs",
                "body":"good clips of Steph Curry's real summer workout.."
        },
        {
            "id":2,
                "name":"Shooting drills 2",
                "thumb":
            "https://kycapitalliving.files.wordpress.com/2014/02/basketball-thumbnail.jpg",
                    "description":
            "Today I wanted to go over my favorite three point basketball shooting drills.",
                    "video":"iPNHkpO-vkw",
                "body":
            "Today I wanted to go over my favorite three point basketball shooting drills."
        },
        {
            "id":3,
                "name":"Shooting drills 3",
                "thumb":
            "http://newsletter.newington.nsw.edu.au/wyvern/files/2013/09/basketball-thumbnail.jpg",
                    "description":
            "If every basketball player worked as hard as me. I would get out of my job.",
                    "video":"UyYzhpgi2TA",
                "body":
            "If every basketball player worked as hard as me. I would get out of my job."
        }
        ]
    },
    {
        "ids":2,
            "category":"Ball Handling",
            "catThumb":
        "https://s-media-cache-ak0.pinimg.com/736x/dd/56/43/dd56432838af2a583a6c22525bf5a18e.jpg",
                "exercises":[
        {
            "id":1,
                "name":"Shooting drills",
                "thumb":
            "http://app.akharinkhabar.ir/AndroidOnlineNewsImage.aspx?id=7531955",
                    "description":
            "good clips of Steph Curry's real summer workout.. ball handling using ropes, floaters,resistance bands, 2 balls drills, vertimax",
                    "video":"MPIuB0rRgsM",
                "body":
            "good clips of Steph Curry's real summer workout.. ball handling using ropes, floaters,resistance bands, 2 balls drills, vertimax"

        }
        ]
    }
    ]
}

【问题讨论】:

  • 最好的方法是将其作为字符串存储在表中,获取并使用 GSon 库将其转换为 json,以便在需要时使用。
  • @Sanoop 不要使用inline code 来突出显示随机术语。

标签: android json sqlite


【解决方案1】:

您应该创建 2 个表。一个用于锻炼类别,包含以下列:ids、category、catThumb,另一个用于锻炼类别,具有列 id、name、thumb、description、video、body 和 id 列,来自锻炼类别表,以便稍后在选择查询中连接这两个表。

【讨论】:

  • matejko219 感谢您的回答。顺便说一句,你知道如何在 sqlite 中按每个类别 id 选择所有练习 id 吗?
  • 如果您了解 SQL,您可以使用rawQuery 方法定义自定义查询。您只需按运动类别 id 连接这两个表,然后选择运动类别 id 等于您想要的值的这些行。
  • String query = "SELECT * FROM exercise e INNER JOIN exercise_category ec ON e.cat_id=ec.id WHERE ec.id=?"; int category_id;//varaible with id db.rawQuery(query, new String[]{String.valueOf(category_id)});
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-28
  • 1970-01-01
  • 1970-01-01
  • 2011-12-17
  • 1970-01-01
相关资源
最近更新 更多