0

i have json data example this :

{
    "datetime": "2019-07-31 15:40:01",
    "Kursi": [
        {
            "kursi_id": 23,
            "kursi_value": 100
        }
    ],
    "Bunga": [
        {
            "bunga_id": 3,
            "bunga_value": "894,9"
        }
    ]
}

how im supposed to do. i want to post this json into my db sql server in one controller. but i have no idea if the data have two object "Kursi" and "Bunga" ?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Sugoro M
  • 3
  • 1
  • 2
    It's not really clear what you're trying to do, or why this JSON presents a problem. – ProgrammingLlama Aug 01 '19 at 08:28
  • [You will get the solution in that link](https://stackoverflow.com/questions/42052672/posting-json-to-controller-mvc-5) – jubair hridoy Aug 01 '19 at 08:32
  • im sorry, im newbie in .net c# and this is the first time i try to make web api. im going to post my data json into database. but i have no idea if the data have multiple object. can u give me a reference to read about web api json c#? – Sugoro M Aug 01 '19 at 08:51

1 Answers1

0

If you want to post data to the controller, create a model that represents you json.

public class MyModel
{
     public DateTime datetime { get; set; }
     public List<Kursi> Kursi { get; set; }
     public List<Bunga> Bunga { get; set; }
}

public class Kurski
{
     public int kursi_id { get; set; }
     public int kursi_value { get; set; }
}

public class Bunga
{
     public int bunga_id { get; set; }
     public string bunga_value { get; set; }
}

Please, do read the documentation. It is not as hard as it looks, and it pays off the hard work.

By the way, ASP.NET Core is an alternative to Web API.

mtanksl
  • 592
  • 6
  • 9