如何将JSON数组保存到MySQL数据库?
为此,您可以使用MySQL中的JSON数据类型。让我们首先创建一个-
create table DemoTable1438 -> ( -> EmployeeDetails json -> );
使用insert在表中插入一些记录-
insert into DemoTable1438 values('[{"EmployeeId":"EMP-101","EmployeeName":"Chris"},{"EmployeeId":"EMP-102","EmployeeName":"David"},{"EmployeeId":"EMP-103","EmployeeName":"Sam"}]');
使用选择显示表中的所有记录-
select * from DemoTable1438;
这将产生以下输出-
+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | EmployeeDetails | +------------------------------------------------------------------------------------------------------------------------------------------------------------+ | [{"EmployeeId": "EMP-101", "EmployeeName": "Chris"}, {"EmployeeId": "EMP-102", "EmployeeName": "David"}, {"EmployeeId": "EMP-103", "EmployeeName": "Sam"}] | +------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)