Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Firebase问题中有两个以上位置的多路径更新_Ios_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

Ios Firebase问题中有两个以上位置的多路径更新

Ios Firebase问题中有两个以上位置的多路径更新,ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,我正在尝试使用Swift SDK在Firebase中一次更新8个位置。不知何故,我设法更新了前两个节点,但其他六个节点只写入父节点,并丢失了相应的路径。下面是我的Firebase DB的数据,更好地说明了这个问题: { "districts" : { "did01" : { "name" : "Teusaquillo", "peopleids" : { "stateid01" : true, "stateid02" :

我正在尝试使用Swift SDK在Firebase中一次更新8个位置。不知何故,我设法更新了前两个节点,但其他六个节点只写入父节点,并丢失了相应的路径。下面是我的Firebase DB的数据,更好地说明了这个问题:

    {
  "districts" : {
    "did01" : {
      "name" : "Teusaquillo",
      "peopleids" : {
        "stateid01" : true,
        "stateid02" : true,
        "stateid03" : true
      },
      "schools" : {
        "schoolid01" : {
          "location" : "norte 50 grados sur 42 ",
          "name" : "Agustiniano Salitre",
          "posts" : {
            "eighth" : {
              "nola" : "hola"
            },
            "eighth-KaG1PA5r7cl70FtBsE4" : "angela",
            "eleventh" : {
              "name" : "haka"
            },
            "eleventh-KaG1PA5r7cl70FtBsE4" : "angela",
            "fifth" : {
              "-KaG1PA5r7cl70FtBsE4" : "angela",
              "dsadsad" : {
                "name" : "Hola"
              },
              "dsfsdfdsf" : true
            },
            "first" : {
              "1" : {
                "author" : "Giovanny Piñeros",
                "text" : "Test"
              },
              "01" : {
                "author" : "Giovanny Piñeros",
                "text" : "Capo"
              },
              "abdffg" : {
                "author" : "Gio",
                "text" : "hola"
              },
              "fdgfdg" : {
                "author" : "Giovanny Piñeros",
                "text" : "Hola"
              },
              "nfdsfds" : {
                "author" : "Giovanny Piñeros",
                "text" : "Vivir de lo que amo"
              },
              "postid01" : {
                "author" : "Papa frita",
                "text" : "Hola",
                "topic" : "Informatics",
                "year" : "first"
              },
              "rtyrty" : {
                "author" : "Giovanny Piñeros",
                "text" : "Si con headapp solo sabia manejar strings y colores, imaginate ahora lo que puedo crear"
              },
              "zsadsa" : {
                "author" : "Gio",
                "text" : "Trest"
              }
            },
            "fourth" : {
              "name" : "hqiq"
            },
            "fourth-KaG1PA5r7cl70FtBsE4" : "angela",
            "ninth" : {
              "hola" : "ahah"
            },
            "ninth-KaG1PA5r7cl70FtBsE4" : "angela",
            "postid01" : {
              "-KaG0b-X9sWXxXlXlmeK" : "angela",
              "-KaG0wNu0Gz5oxu4__Ej" : "angela",
              "author" : "Papa frita",
              "likes" : {
                "userid01" : "Giovanny Piñeros"
              },
              "text" : "hola",
              "topic " : "Informatics",
              "year" : "first"
            },
            "postid02" : {
              "autor" : "Directive",
              "text" : "Free for the day",
              "topic" : "General",
              "year" : "all"
            },
            "second" : {
              "-KaFnTl89keEOx3UpnGJ" : true,
              "-KaFpLsNy6z-TshUJONx" : true,
              "-KaFpMwBdHqBwsq-k6i3" : true,
              "-KaFpz6qwQ2uTevvpxXo" : true,
              "-KaFq21Qdv-Z6KFcu8ZT" : true,
              "-KaFq34fN1-ZxO0EtqEw" : true,
              "-KaFv7a9JvEjPLDDzT8S" : "angela",
              "-KaFw9Hb6OjIRzeP6jdk" : "angela",
              "-KaFwAFvFoVEvpzaaVO2" : "angela",
              "-KaFwAboyWtEOG3NU1yZ" : "angela",
              "-KaFwAji3rR6e5fCHjFc" : "angela",
              "-KaFwAmisIA5i4UhvcRw" : "angela",
              "-KaFyJHEqDzoVoj_zUWI" : "angela",
              "-KaFy_cqf1mvTxRGN5j_" : "angela",
              "-KaG-_r4ql2YVc19gbkt" : "angela",
              "dsfsdf" : {
                "hola" : "dfsad"
              }
            },
            "seventh" : {
              "name" : "dsfhksd"
            },
            "sixth" : {
              "name" : "haaka"
            },
            "tenth" : {
              "name" : "hola"
            },
            "tenth-KaG1PA5r7cl70FtBsE4" : "angela",
            "third" : {
              "-KaFnTl89keEOx3UpnGJ" : true,
              "-KaFpLsNy6z-TshUJONx" : true,
              "-KaFpMwBdHqBwsq-k6i3" : true,
              "-KaFpz6qwQ2uTevvpxXo" : true,
              "-KaFq21Qdv-Z6KFcu8ZT" : true,
              "-KaFq34fN1-ZxO0EtqEw" : true,
              "-KaFv7a9JvEjPLDDzT8S" : "angela",
              "-KaFw9Hb6OjIRzeP6jdk" : "angela",
              "-KaFwAFvFoVEvpzaaVO2" : "angela",
              "-KaFwAboyWtEOG3NU1yZ" : "angela",
              "-KaFwAji3rR6e5fCHjFc" : "angela",
              "-KaFwAmisIA5i4UhvcRw" : "angela",
              "-KaFyJHEqDzoVoj_zUWI" : "angela",
              "-KaFy_cqf1mvTxRGN5j_" : "angela",
              "-KaG-_r4ql2YVc19gbkt" : "angela",
              "-KaG0b-X9sWXxXlXlmeK" : "angela",
              "-KaG0wNu0Gz5oxu4__Ej" : "angela",
              "-KaG1PA5r7cl70FtBsE4" : "angela",
              "author" : "hola"
            },
            "twelfth" : {
              "name" : "haoao"
            }
          },
          "users" : {
            "userid01" : {
              "likes" : {
                "postid01" : true
              },
              "name" : "Giovanny Piñeros",
              "rol" : "student",
              "stateid" : "stateid01",
              "year" : "first"
            },
            "userid03" : {
              "Posts" : {
                "postid01" : {
                  "fjsldkfj" : "nombre",
                  "texzto" : "fksdjh"
                }
              },
              "name" : "Papa frita",
              "rol" : "teacher"
            }
          }
        }
      }
    },
    "did02" : {
      "name" : "Austin",
      "peopleids" : {
        "stateid04" : true,
        "stateid05" : true,
        "stateid06" : true
      }
    }
  },
  "eventos" : {
    "attendiees" : {
      "adshfksafjh" : "giovanny"
    },
    "nombre" : "fiesta"
  },
  "queue" : {
    "specs" : {
      "specstest" : 0
    },
    "tasks" : {
      "ido" : {
        "_error_details" : {
          "error" : "Task was malformed",
          "error_stack" : "Error: Task was malformed\n    at Object.update (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-queue/dist/lib/queue_worker.js:453:27)\n    at Ih (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:233:395)\n    at R.h.transaction (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:248:466)\n    at /Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-queue/dist/lib/queue_worker.js:446:30\n    at c (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:135:58)\n    at /Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:126:791\n    at Ac (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:63:165)\n    at jf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:126:215)\n    at hf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:125:479)\n    at vf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:231:426)",
          "original_task" : 0
        },
        "_state" : "error",
        "_state_changed" : 1482958978549
      }
    }
  },
  "usuarios" : {
    "hvlksdj" : {
      "edad" : 26,
      "nombre" : "giovanny"
    }
  }
}
如您所见,子节点
posid01
second
会更新,从而创建一个新的子节点,但对于其他位置,这不会发生

这是我的密码。我根据Firebase指南做了以下工作:

let ref = FIRDatabase.database().reference()
var newPost = ref.childByAutoId()
let newKey = newPost.key  
let dict = ["districts/did01/schools/schoolid01/posts/fifth/\(newKey)" : "test","districts/did01/schools/schoolid01/posts/third/\(newKey)": "test",
                "districts/did01/schools/schoolid01/posts/fourth\(newKey)": "test","districts/did01/schools/schoolid01/posts/postid02\(newKey)": "test",
                "districts/did01/schools/schoolid01/posts/sixth\(newKey)": "test","districts/did01/schools/schoolid01/posts/seventh\(newKey)": "test",
        "districts/did01/schools/schoolid01/posts/eighth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/ninth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/tenth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/eleventh\(newKey)": "test", "districts/did01/schools/schoolid01/posts/postid04\(newKey)" : "test"]

ref.updateChildValues(dict, withCompletionBlock: {(Error,FIRDatabaseReference) in
    if(Error == nil){
    print("EXITO :)")
    }else{
    print("PAILA :(")
    }
    })

我刚刚发现了错误,太简单了,我在字典上犯了一个错误。未更新的位置是这样写的:

"districts/did01/schools/schoolid01/posts/fourth\(newKey)": "test"

正如您所看到的,最后一部分在newKey之前缺少一个“/”

您的问题中包含了JSON树的图片。请将其替换为实际的JSON文本,您可以通过单击中的导出JSON链接轻松获取。将JSON作为文本使其具有可搜索性,允许我们轻松使用它来测试您的实际数据,并在我们的答案中使用它,这通常是一件好事。@FrankvanPuffelen谢谢您,我将JSON发布到您的邮箱@FrankvanPuffelen and AL。为了您的帮助,我刚刚发现了错误。