如何使用外键将JSON连接在一起

时间:2013-04-04 13:10:06

标签: javascript json

我需要使用外键链接一些JSON。例如,我有三个JSON:

JSON 1 - 用户

{
   id: 23,
   name: "Agata"
}

JSON 2 - 幻灯片

{
   title: "lalala",
   content: "lalalalalal",
   member: [
      {
        //here I would like to add json user  id: 23
      }
   ]
}

JSON 3 - 评论

{
   title: "nanana",
   author: // here I would like to add json user id : 23
}

你有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我在考虑你有三个包含每个JSON对象的变量,你可以这样做:

JSON 1 - 用户

var json1 = {
   id: 23,
   name: "Agata"
}

JSON 2 - 幻灯片

var json2 = {
   title: "lalala",
   content: "lalalalalal",
   member: [
      json1
   ]
}

JSON 3 - 评论

var json3 = {
   title: "nanana",
   author: json1
}