导入JSON至Firebase Realtime Database时遇无效JSON错误求助
解决Firebase Realtime Database导入JSON报错问题
针对你遇到的导入报错(Invalid JSON - Keys cannot be empty or contain $#[]./),尽管JSON格式验证通过,但Firebase对键名有额外的严格检查,以下是排查和解决方向:
排查隐藏不可见字符:部分文本编辑器会在键名或值中插入零宽空格等不可见Unicode字符,这些字符不会被JSON验证工具检测到,但会触发Firebase的键名规则。建议用支持显示控制字符的编辑器(如VS Code开启"显示控制字符"选项)检查,或把内容复制到纯文本编辑器重新保存为UTF-8格式。
区分字符串"null"与原生null值:你当前设置的
"explanationImage":"null"是字符串类型,虽然语法合法,但Firebase导入工具可能对这种写法存在异常判断。如果需要表示空值,建议替换为"explanationImage":null(不带双引号的原生null)后重试。确认导入目标路径合法性:检查Firebase控制台中选择的导入目标节点路径,确保路径中不包含
$#[]/.这些禁止字符,同时确认导入方式(替换/合并)是否会导致节点键冲突。分批导入排查问题条目:将JSON数组拆分为多个小批次(比如前5条和后5条)分别导入,定位是否是某个特定条目引发的错误,再针对该条目做细节检查。
你的JSON内容如下:
{"questionAndItsAnswers":[{"id":1,"question":"In 2006, the International Astronomical Union (IAU) reclassified this object as a dwarf planet:","answerChoices":["Pluto","Mercury","the Moon","Pallas"],"correctAnswerIndex":0,"hint":"Hint: The Moon is larger than any dwarf planet.","answerAndExplanation":"Pluto. Pluto’s former status as a planet was challenged by the discovery of similar-sized objects in the Kuiper belt.","explanationImage":"gs://spaceinvadersandquiz.appspot.com/Pluto14July2015NewHorizons1024x1024Qual90.jpg"},{"id":2,"question":"This planet is a gas giant:","answerChoices":["Mars","Saturn","Uranus","Neptune"],"correctAnswerIndex":1,"hint":"Hint: Uranus and Neptune are now usually classified as ice giants.","answerAndExplanation":"Saturn. Jupiter and Saturn are classified as gas giants. Mars is classified as a terrestrial planet (along with Mercury, Venus, and Earth). Uranus and Neptune are now usually classified as ice giants.","explanationImage":"gs://spaceinvadersandquiz.appspot.com/SaturnHubble4July2020Enceladus(below)Mimas(rt)512x512Qual90.jpg"},{"id":3,"question":"This is the most massive object in the Solar System:","answerChoices":["the asteroid belt","the Kuiper belt","the Sun","solar wind"],"correctAnswerIndex":2,"hint":"Hint: The asteroid belt is less massive than the Kuiper belt.","answerAndExplanation":"The Sun. The Sun contains approximately 99.86% of the mass of the Solar System.","explanationImage":"gs://spaceinvadersandquiz.appspot.com/SunAndProminenceSTEREOspacecraft29Sept2008_512x512Qual90.jpg"},{"id":4,"question":"This planet is an ice giant:","answerChoices":["Mercury","Jupiter","Saturn","Uranus"],"correctAnswerIndex":3,"hint":"Hint: This planet, though visible to the naked eye, was unrecognized as a planet until 1781 due to its dimness and slow apparent movement.","answerAndExplanation":"Uranus. Uranus and Neptune are classified as ice giant planets. Jupiter and Saturn are classified as gas giant planets. Mercury is one of the terrestrial planets.","explanationImage":"gs://spaceinvadersandquiz.appspot.com/UranusHubble11Dec2009BandsDarkSpot256x256Qual90.jpg"},{"id":5,"question":"This is a terrestrial planet:","answerChoices":["Venus","Jupiter","Neptune","Pluto"],"correctAnswerIndex":0,"hint":"Hint: Neptune is classified as an ice giant planet.","answerAndExplanation":"Venus. Mercury, Venus, Earth, and Mars are the terrestrial planets – planets consisting primarily of metals or silicate rocks. Jupiter and Saturn are gas giant planets. Uranus and Neptune are ice giant planets. Pluto was reclassified as a dwarf planet in 2006.","explanationImage":"gs://spaceinvadersandquiz.appspot.com/VenusMariner10ContrastEnhanced7Feb1974_1024x1024Qual90.jpg"},{"id":6,"question":"The plane of the Earth’s orbit around the Sun is the:","answerChoices":["equator","ecliptic","equinox","ellipse"],"correctAnswerIndex":1,"hint":"Hint: An equinox occurs around 20 March and 23 September when the center of the Sun is directly over the equator.","answerAndExplanation":"Ecliptic. For an observer on Earth, the ecliptic is the annual path of the Sun viewed against the background stars.","explanationImage":"null"},{"id":7,"question":"Roughly 73% of the Sun’s mass consists of this:","answerChoices":["iron","nickel","hydrogen","helium"],"correctAnswerIndex":2,"hint":"Hint: Helium accounts for about 25% of the Sun’s mass.","answerAndExplanation":"Hydrogen.","explanationImage":"null"},{"id":8,"question":"The center of mass of multiple bodies orbiting each other is the:","answerChoices":["orbital node","semi-major axis","Roche limit","barycenter"],"correctAnswerIndex":3,"hint":"Hint: This term derives from an Ancient Greek expression for ‘heavy center.’","answerAndExplanation":"Barycenter. The dwarf planet Pluto and its largest moon, Charon, are sometimes considered a binary system because the center of mass of their orbits, that is, their barycenter, lies between them and outside of either body, whereas the barycenter of the Earth-Moon system lies within the Earth.","explanationImage":"null"},{"id":9,"question":"The nearest star system to the Sun is:","answerChoices":["Alpha Centauri","Algol","Sirius","Polaris"],"correctAnswerIndex":0,"hint":"Hint: Polaris (also called the ‘North Star’ or ‘Pole Star’) is not especially close to the Solar System but is very close to the Earth’s celestial north pole.","answerAndExplanation":"Alpha Centauri. Alpha Centauri is a triple star system 4.37 light-years (1.34 parsecs) from the Sun.","explanationImage":"null"},{"id":10,"question":"These objects have masses less than the least massive stars but greater than the most massive planets:","answerChoices":["dwarf planets","brown dwarfs","star clusters","gas giants"],"correctAnswerIndex":1,"hint":"Hint: Jupiter and Saturn are gas giants (gas giant planets).","answerAndExplanation":"Brown dwarfs. Brown dwarfs, which are not necessarily brown, have masses from roughly 13 to 80 times that of Jupiter but lack the mass to sustain nuclear fusion. They are sometimes called ‘failed stars.’","explanationImage":"null"}]}
内容的提问来源于stack exchange,提问作者WPWPWP
相关产品推荐
相关产品推荐

