locked
I have multiple tables in JSON format RRS feed

  • Question

  • User387423 posted

    I have multiple tables in JSON format I want to retrieve data by table-wise how to do can any one help me

    Tuesday, September 3, 2019 6:41 AM

Answers

  • User369978 posted

    You need Newtonsoft.Json and SQLite.NET .

    1. Use json2csharp to create model with json string.

    2. Deserialize json to model class .

       Stock m = JsonConvert.DeserializeObject<Stock>(json);
      
    3. Save Data into SQL

      var db = new SQLiteConnection (dbPath);
      db.CreateTable<Stock> ();
      db.Insert (newStock); // after creating the newStock object
      
    4. Retrieve Data

      var stock = db.Get<Stock>(5); // primary key id of 5
      var stockList = db.Table<Stock>();
      

    Refer

    https://docs.microsoft.com/en-us/xamarin/ios/data-cloud/data/using-sqlite-orm https://docs.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm https://www.newtonsoft.com/json/help/html/Introduction.htm

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, September 3, 2019 8:34 AM

All replies

  • User346273 posted

    do you have the tables Models ?

    Tuesday, September 3, 2019 7:37 AM
  • User387423 posted

    @Xigmond said: do you have the tables Models ?

    no

    {"Table":[{"dayspresent":11.0,"totalfee":2500.0,"amountpaid":2150.0,"balance":350.0}],"Table1":[{"ptid":625,"fee":350.0,"treatment":"SWD,IFT+SPINAL EXTENSION EXERCISES","diagnosis":"LBA","complaints":"BACK PAIN"}],"Table2":[{"id":111,"date":"01-06-2018","amountpaid":0.0},{"id":111,"date":"03-06-2018","amountpaid":200.0},{"id":111,"date":"04-06-2018","amountpaid":200.0},{"id":111,"date":"05-06-2018","amountpaid":200.0},{"id":111,"date":"26-05-2018","amountpaid":600.0},{"id":111,"date":"27-05-2018","amountpaid":0.0},{"id":111,"date":"28-05-2018","amountpaid":0.0},{"id":111,"date":"29-05-2018","amountpaid":600.0},{"id":111,"date":"31-05-2018","amountpaid":0.0},{"id":625,"date":"02-09-2019","amountpaid":350.0},{"id":625,"date":"03-09-2019","amountpaid":0.0}]}

    i am getting data in above format

    Tuesday, September 3, 2019 8:17 AM
  • User369978 posted

    You need Newtonsoft.Json and SQLite.NET .

    1. Use json2csharp to create model with json string.

    2. Deserialize json to model class .

       Stock m = JsonConvert.DeserializeObject<Stock>(json);
      
    3. Save Data into SQL

      var db = new SQLiteConnection (dbPath);
      db.CreateTable<Stock> ();
      db.Insert (newStock); // after creating the newStock object
      
    4. Retrieve Data

      var stock = db.Get<Stock>(5); // primary key id of 5
      var stockList = db.Table<Stock>();
      

    Refer

    https://docs.microsoft.com/en-us/xamarin/ios/data-cloud/data/using-sqlite-orm https://docs.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm https://www.newtonsoft.com/json/help/html/Introduction.htm

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, September 3, 2019 8:34 AM
  • User387423 posted

    @ColeX said: You need Newtonsoft.Json and SQLite.NET .

    1. Use json2csharp to create model with json string.

    2. Deserialize json to model class .

       Stock m = JsonConvert.DeserializeObject<Stock>(json);
      
    3. Save Data into SQL

      var db = new SQLiteConnection (dbPath);
      db.CreateTable<Stock> ();
      db.Insert (newStock); // after creating the newStock object
      
    4. Retrieve Data

      var stock = db.Get<Stock>(5); // primary key id of 5
      var stockList = db.Table<Stock>();
      

    Refer

    https://docs.microsoft.com/en-us/xamarin/ios/data-cloud/data/using-sqlite-orm https://docs.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm https://www.newtonsoft.com/json/help/html/Introduction.htm

    I am not using sqllite and using RestAPI to store the data

    Tuesday, September 3, 2019 10:19 AM
  • User369978 posted

    How you want to retrieve the data ? Could you elaborate more about table-wise ?

    Tuesday, September 3, 2019 2:41 PM