我已经浏览了维基百科,并用Google搜索并阅读了官方文档,但我仍然没有达到我真正理解JSON是什么的原因,以及为什么我会使用它.
我一直在使用PHP,MySQL和Javascript/HTML构建应用程序,如果JSON可以做些什么来让我的生活更轻松或我的代码更好或我的用户界面更好,那么我想知道它.有人可以给我一个简洁的解释吗?
我有两个表,表1有2个字段(question_pk,question_name),表2有4个字段(ans_pk,options,question_fk和right_answer).我想像以下结构一样创建json
{
"type": "quiz",
"name": "Brand Colors",
"description": "Can you identify these brands by the background color?",
"questions": [
{
"name": "Can you identify this color?",
"description": "#ea4c89",
"answers": [
{
"name": "Dribbble",
"description": "dribbble.png",
"weight": 1
},
{
"name": "Amazon",
"description": "amazon.png",
"weight": 0
},
{
"name": "Apple",
"description": "apple.png",
"weight": 0
}
]
},
{
"name": "Can you identify this color?",
"description": "#3d9ae8",
"answers": [
{
"name": "Youtube",
"description": "youtube.png",
"weight": 0
},
{
"name": "Dropbox",
"description": …Run Code Online (Sandbox Code Playgroud) 我有2个表,都有自己的自动递增ID,这当然是主键.
当我想创建第3个表来建立这两个表之间的关系时,我总是有一个错误.
第一个是关于你只能有一个自动递增的列,第二个是当我从那些2中删除auto_increment语句时发生的,因此sql不允许我将它们作为外键,因为类型匹配失败.
有没有办法可以创建关系表而不会丢失自动增量功能?
另一种可能的(但不是优选的)解决方案可能是第一个表中有另一个主键,当然是用户的用户名,而不是自动增量语句.这是不可避免的吗?
提前致谢.