How to deserialize json Using Newtonsoft?

MonalishaMonalisha Member ✭✭

I am new to Xamarin and don't have muh knowlwdge on json parsing. Please anyone suggest me how to deserialize the below json, so that I can get all bill object. I wrote C# code like this, but getting error

public class Bills
{
public string status { get; set; }
public IList bill { get; set; }

    public async static Task<List<Bill>> GetBills()
    {
        List<Bills> bills = new List<Bills>();

        Uri uri = new Uri(Constants.Bills_URL);

        using (HttpClient client = new HttpClient())
        {
            var response = await client.GetAsync(uri);
            var content = await response.Content.ReadAsStringAsync();

            bills = JsonConvert.DeserializeObject<Bills>(content);
        }
        return bills;
    }
}

This is the json, that i want to deserialize
{
"status": "success",
"bill": [
{
"bill_id": "1",
"transaction_date": "2018-04-01 06:00:00",
"billing_date": "2018-04-01",
"vehicle_id": "1",
"customer_id": "2",
"fuel_id": "1",
"fuel_unit_id": "1",
"fuel_price_id": "1",
"price_per_unit": "69.97",
"quantity": "12732.27",
"amount": "890877.00",
"received_amount": "0.00",
"advance_amount": "0.00",
"net_amount": "890877.00",
"status": "success",
"station_id": "1",
"customer_name": "Anerr",
"vehicle_number": "TS 30 T 1157",
"fuel_name": "Diesel",
"station_name": "HSDrtr I"
},
{
"bill_id": "2",
"transaction_date": "2018-04-01 06:00:00",
"billing_date": "2018-04-01",
"vehicle_id": "2",
"customer_id": "1",
"fuel_id": "1",
"fuel_unit_id": "1",
"fuel_price_id": "0",
"price_per_unit": "69.97",
"quantity": "10793.31",
"amount": "755208.00",
"received_amount": "0.00",
"advance_amount": "0.00",
"net_amount": "755208.00",
"status": "success",
"station_id": "2",
"customer_name":"Sangram",
"vehicle_number": "dff 6558",
"fuel_name": "Diesel",
"station_name": "HSDff II"
}
]

Best Answer

Answers

Sign In or Register to comment.