.net core json files

Asked

Viewed 245 times

1

I am making a simple web application, it will read a json file:

{
    "hotelName" : "Jumeirah Creekside Hotel",
    "thumb": "https://loremflickr.com/130/100/dubai",
    "stars" : 5,
    "location" : "Garghoud",
    "city": {
        "id": "132",
        "name": "Dubai"
    },
    "country": "UAE",
    "date": "2019-03-17",
    "price": 800,
    "class": "First Class",
    "guest": 1
  },

And I need to use the data from that file on a web page. I’ve already created the Json classes. I’m using the Asp net core mvc, and I don’t know where to call the read method of the same file. I am using File to read the file, and want to use Newtonsoft to convert, I think my error is even in mvc structure.

    namespace MyTrips
{
    public class Host
    {
        public string hotelName { get; set; }
        public string thumb { get; set; }
        public int stars { get; set; }
        public string location { get; set; }
        public City city { get; set; }
        public string country { get; set; }
        public string date { get; set; }
        public int price { get; set; }
        public string @class { get; set; }
        public int guest { get; set; }
    }
}

namespace MyTrips
{
    public class City
    {
        public object id { get; set; }
        public string name { get; set; }
    }
}
  • And that , at the end of Json? you are receiving only one object or a collection?

  • Include the code from where you’re trying to read the file

1 answer

0

The JSON mapping posted is correct with a caveat that has a @class remove that @ and something else is the "," at the end of the file. Another thing you’re sure that type Price should really be int? It makes sense to be a Double.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.