我已将json数组值存储到类中,并使用下面的代码对其进行反序列化。如何将json数据插入sqlite?
[{"ID":1,"name":"Shyam","class":"a"},{"ID":2,"name":"Bran","class":"b"}]
using Newtonsoft.Json;
using SQLitePCL;
var StudentJSON = await response.Content.ReadAsStringAsync();
var jsonData = JsonConvert.DeserializeObject<List<StudentClass>>(StudentJSON);
using (var connection = new SQLiteConnection(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\Student_DB.sqlite"))
{
using (var statement = connection.Prepare(@"INSERT INTO Student (ID,name,class)
VALUES(?, ?,?);"))
{
// Inserts data.
}
}
答案 0 :(得分:0)
使用'SQLite.Net'可以将数据插入sqlite表中,
// Insert the new student record in the Student table.
string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "StudentDb.sqlite");
public void Insert(Student std)
{
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath))
{
conn.RunInTransaction(() =>
{
conn.Insert(std);
});
}
}