在Ionic 3移动应用程序中,是否可以将response.json()
值存储到sqlite数据库中,并且在检索时可以解析并转换为对象?
this.service.getEmployeeDtls().subscribe((response) => {
if (response.status == 200) {
let empDtls= response.json();
// want to store the empDtls to sqlite database as it is
}
如果这不可能,那么唯一的办法就是我们必须解析JSON值,然后一个一个地插入到数据库中。
答案 0 :(得分:0)
我有解决方案,可以将数据存储在SQLite数据库中。
var city:City = new City(response.json());
创建一个模态类并分配给它。
export class City {
cityId: numbner;
cityName: string;
constructor(json?: any) {
if (json) {
Object.assign(this, json);
}
}
getCityId() {
}
setCityId() {
}
getCityName() {
}
setCityName() {
}
....
}
}
然后我们可以创建一个表并插入
之类的值city.cityId,city.cityName
在SQLite数据库中。一切正常。
谢谢