firebase mysql,将数据从MySQL迁移到Firebase

I have an existing PHP/MySQL app which I am trying to migrate to AngularJS/Firebase, just as a way to learn these newer technologies.

The app has its own schema of tables in MySQL. One such table looks something like:

CREATE TABLE `dictionary` (

`id` int(11) unsigned NOT NULL AUTO_INCREMENT,

`word` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,

`wordmeaning` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,

`wordlength` int(11) unsigned NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

My question is: how do I migrate this table structure, and the data in it, from MySQL to Firebase?

I have tried exporting the data into a JSON string via a query such as:

SELECT CONCAT("[",

GROUP_CONCAT(

CONCAT("{id:'",id,"',"),

CONCAT("word:'",word,"',"),

CONCAT("wordmeaning:'",wordmeaning,"',"),

CONCAT("wordlength:'",wordlength,"'}")

)

,"]")

AS json FROM dictionary;

This gives a valid JSON string such as:

[{id:'1',word:'cat',wordmeaning:'a mammal species',wordlength:'3'},

{id:'2',word:'catapult',wordmeaning:'throwing device',wordlength:'8'},

{id:'3',word:'cart',wordmeaning:'something to carry things in',wordlength:'4'}]

I saved this in a file and tried to import the file from Firebase, using the Import JSON button, to which I got:Error parsing JSON data. Please validate your input. (The JSON string is valid. I checked it at http://jsonviewer.stack.hu/)

Any ideas about what I could be doing wrong? I am assuming that Firebase can handle such structures and the data in them.

Thanks.

解决方案

Your JSON is not valid. Change it to this to be valid:

[{"id":"1","word":"cat","wordmeaning":"a mammal species","wordlength":"3"},

{"id":"2","word":"catapult","wordmeaning":"throwing device","wordlength":"8"},

{"id":"3","word":"cart","wordmeaning":"something to carry things in","wordlength":"4"}]

So these are the changes:

use double-quotes instead of single-quotes

put (double) quotes around the keys, not just the values

You may want to consider not quoting the values of id and wordlength, since these properties seem to be numeric.

Edit

These two online tools seem to validate the JSON correctly (or at least in line with what Firebase expects):

The second one also pretty prints the JSON, so that might be a reason to prefer one or the other.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值