Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:56:09+00:00 2026-06-08T08:56:09+00:00

I am using a web service which returns data into JSON in following format

  • 0

I am using a web service which returns data into JSON in following format

{
    "responseId": 2933574,
    "availableHotels": [
        {
            "processId": "HC-65870953",
            "hotelCode": "UKI9E6",
            "availabilityStatus": "InstantConfirmation",
            "totalPrice": 971,
            "totalTax": 0,
            "totalSalePrice": 0,
            "currency": "EUR",
            "boardType": "Bed & Continental Breakfast",
            "rooms": [
                {
                    "roomCategory": "Triple Room",
                    "paxes": [
                        {
                            "paxType": "Adult",
                            "age": 30
                        },
                        {
                            "paxType": "Adult",
                            "age": 30
                        },
                        {
                            "paxType": "Child",
                            "age": "6"
                        }
                    ],
                    "totalRoomRate": 486,
                    "ratesPerNight": [
                        {
                            "date": "2012-07-20",
                            "amount": 163
                        },
                        {
                            "date": "2012-07-21",
                            "amount": 163
                        },
                        {
                            "date": "2012-07-22",
                            "amount": 160
                        },
                        {
                            "date": "2012-07-23",
                            "amount": 0
                        }
                    ]
                },
                {
                    "roomCategory": "Triple Room",
                    "paxes": [
                        {
                            "paxType": "Adult",
                            "age": 30
                        },
                        {
                            "paxType": "Adult",
                            "age": 30
                        },
                        {
                            "paxType": "Child",
                            "age": "8"
                        }
                    ],
                    "totalRoomRate": 485,
                    "ratesPerNight": [
                        {
                            "date": "2012-07-20",
                            "amount": 163
                        },
                        {
                            "date": "2012-07-21",
                            "amount": 163
                        },
                        {
                            "date": "2012-07-22",
                            "amount": 160
                        },
                        {
                            "date": "2012-07-23",
                            "amount": -1
                        }
                    ]
                }
            ]
        },
        {
            "processId": "HH-22003963",
            "hotelCode": "UKPDNN",
            "availabilityStatus": "InstantConfirmation",
            "totalPrice": 1085,
            "totalTax": 0,
            "totalSalePrice": 0,
            "currency": "EUR",
            "boardType": "Bed and Breakfast",
            "rooms": [
                {
                    "roomCategory": "Triple Room",
                    "paxes": [
                        {
                            "paxType": "Adult",
                            "age": 30
                        },
                        {
                            "paxType": "Adult",
                            "age": 30
                        },
                        {
                            "paxType": "Child",
                            "age": "6"
                        }
                    ],
                    "totalRoomRate": 544,
                    "ratesPerNight": [
                        {
                            "date": "2012-07-20",
                            "amount": 136
                        },
                        {
                            "date": "2012-07-21",
                            "amount": 136
                        },
                        {
                            "date": "2012-07-22",
                            "amount": 136
                        },
                        {
                            "date": "2012-07-23",
                            "amount": 136
                        }
                    ]
                },
                {
                    "roomCategory": "Triple Room",
                    "paxes": [
                        {
                            "paxType": "Adult",
                            "age": 30
                        },
                        {
                            "paxType": "Adult",
                            "age": 30
                        },
                        {
                            "paxType": "Child",
                            "age": "8"
                        }
                    ],
                    "totalRoomRate": 541,
                    "ratesPerNight": [
                        {
                            "date": "2012-07-20",
                            "amount": 136
                        },
                        {
                            "date": "2012-07-21",
                            "amount": 136
                        },
                        {
                            "date": "2012-07-22",
                            "amount": 136
                        },
                        {
                            "date": "2012-07-23",
                            "amount": 133
                        }
                    ]
                }
            ]
        }
    ],
    "totalFound": 2,
    "searchId": "QG-67623913"
}

Now I have a class defined as following:

 public class getAvailableHotelResponse
    {
        public getAvailableHotelResponse();

        public hotel[] availableHotels { get; set; }
        [SoapElement(DataType = "integer")]
        public string responseId { get; set; }
        public string searchId { get; set; }
        [SoapElement(DataType = "integer")]
        public string totalFound { get; set; }
    }

And the hotel class is as follows:

public class hotel
    {
        public hotel();

        public string availabilityStatus { get; set; }
        public string boardType { get; set; }
        public string currency { get; set; }
        public string hotelCode { get; set; }
        public string processId { get; set; }
        public roomResponse[] rooms { get; set; }
        [SoapElement(DataType = "integer")]
        public string specialDeal { get; set; }
        public float totalPrice { get; set; }
        [SoapIgnore]
        public bool totalPriceSpecified { get; set; }
        public float totalSalePrice { get; set; }
        [SoapIgnore]
        public bool totalSalePriceSpecified { get; set; }
        public float totalTax { get; set; }
        [SoapIgnore]
        public bool totalTaxSpecified { get; set; }
    }

And the roomResponse class is as follows:

public class roomResponse
    {
        public roomResponse();

        public pax[] paxes { get; set; }
        public dailyRate[] ratesPerNight { get; set; }
        public string roomCategory { get; set; }
        public float totalRoomRate { get; set; }
        [SoapIgnore]
        public bool totalRoomRateSpecified { get; set; }
    }

And pax class is as follows:

 public class pax
    {
        public pax();

        [SoapElement(DataType = "integer")]
        public string age { get; set; }
        public string firstName { get; set; }
        public string lastName { get; set; }
        public string paxType { get; set; }
        public string title { get; set; }
    }

And dailyRate class is as follows:

 public class dailyRate
    {
        public dailyRate();

        public float amount { get; set; }
        [SoapIgnore]
        public bool amountSpecified { get; set; }
        [SoapElement(DataType = "date")]
        public DateTime date { get; set; }
        [SoapIgnore]
        public bool dateSpecified { get; set; }
    }

Edit

getAvailableHotelResponse h = new getAvailableHotelResponse();

h = (getAvailableHotelResponse)Newtonsoft.Json.JsonConvert.DeserializeObject(text);

I tried this and it’s throwing the following error:

Unable to cast object of type ‘Newtonsoft.Json.Linq.JObject’ to type
‘hotelspro.getAvailableHotelResponse’.

There is a really complex structure of JSON, so how do I convert this to my objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:56:10+00:00Added an answer on June 8, 2026 at 8:56 am

    Remove non-compilable constructors like public pax(); and just use

    var availHotels = JsonConvert.DeserializeObject<getAvailableHotelResponse>(text);
    

    that’s all.

    In fact, you wouldn’t even need to declare this bunch of classes(getAvailableHotelResponse, hotel,roomResponse,pax,dailyRate etc.) if you made use of dynamic. For ex,

    dynamic response = Newtonsoft.Json.JsonConvert.DeserializeObject(text);
    
    foreach (var hotel in response.availableHotels)
    {
        Console.WriteLine(hotel.processId);
        foreach (var room in hotel.rooms)
        {
            Console.WriteLine("\t" + room.roomCategory);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a web service that returns JSON data. test.com/incident.do?JSON&sysparm_action=getRecords Loading this URL
I'm using a web service which returns a list of products. I created a
I have a web-service running on Windows Azure which returns JSON that I consume
I'm trying to execute a web service which returns a DataTable with the following
I am using WCF Web API service to publish some data via Json and
I have a xml web service which I would like to track using Google
I have created a RESTful PHP web service using Lithium which contains comments, each
I have an ASP.net web service that I'm using for a web application which
I am trying to call a web service (using nusoap ), which work well
I am creating an application which involves so many web-service calls. I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.