How to convert JSON to C# Class

Today I found one very good tool to convert JSON data to C# class.

Please go to this link: http://json2csharp.com/

You just paste the JSON data, and it will give you the class for each element in the JSON data.

Example JSON Data :

Note: This example JSON data from TripAdvisor API.

  {  
"address_obj": {
"street1": "Lot PTB22819 ",
"street2": "Jalan Skudai",
"city": "Johor Bahru",
"state": "Johor",
"country": "Malaysia",
"postalcode": "80200",
"address_string": "Lot PTB22819 Jalan Skudai, Johor Bahru 80200 Malaysia"
},
"latitude": "1.485111",
"rating": "4.0",
"description": "Staying true to our unique no frills concept, we provide you a good night's sleep at outstanding value. Our hotels come with high quality beds, power showers, 24-hour security system, and are conveniently located near transportation hubs and popular local attractions. Unnecessary costs are kept at bay by eliminating facilities that you might not need such as swimming pools, gyms, spa rooms etc.\n\nTune Hotel Danga Bay Johor offers easy access to Asia's first LEGOLAND(R) theme park which is 15-minutes' drive away, or you can hitch a ride with the shuttle bus provided by our hotel. Kids would love exploring the Sanrio Hello Kitty Town, Little Big Club, Thomas and Friends, and Barney at Puteri Harbour which is next to LEGOLAND(R). Daily shuttles transfers are also available to the doorstep of Resorts World Sentosa and Universal Studios Singapore. If you want to just shop, don't miss out on an exquisite shopping experience at Johor Premium Outlets!",
"location_id": "1770042",
"trip_types": [
{
"name": "business",
"value": "49",
"localized_name": "Business"
},
{
"name": "couples",
"value": "120",
"localized_name": "Couples"
},
{
"name": "solo",
"value": "47",
"localized_name": "Solo travel"
},
{
"name": "family",
"value": "278",
"localized_name": "Family"
},
{
"name": "friends",
"value": "94",
"localized_name": "Friends getaway"
}
],
"reviews": [
{
"id": "281355546",
"lang": "en",
"location_id": "1770042",
"published_date": "2015-06-19T10:11:02-0400",
"rating": 3,
"helpful_votes": "0",
"rating_image_url": "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/s3.0-11068-5.png",
"url": "http://www.tripadvisor.com/ShowUserReviews-g298278-d1770042-r281355546-Tune_Hotel_Danga_Bay-Johor_Bahru_Johor_Bahru_District_Johor.html#review281355546",
"trip_type": "Friends getaway",
"travel_date": "2014-07",
"text": "The hotel is out of the main city though you have taxi on call. There are only a couple of eating places. The rooms are very small . we stayed only because we were there for a night and had to go to...",
"user": {
"username": "Dinesh C",
"user_location": {
"name": null,
"id": null
}
},
"title": "Stay if you are short of funds"
},
{
"id": "281171322",
"lang": "en",
"location_id": "1770042",
"published_date": "2015-06-18T14:06:06-0400",
"rating": 1,
"helpful_votes": "0",
"rating_image_url": "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/s1.0-11068-5.png",
"url": "http://www.tripadvisor.com/ShowUserReviews-g298278-d1770042-r281171322-Tune_Hotel_Danga_Bay-Johor_Bahru_Johor_Bahru_District_Johor.html#review281171322",
"trip_type": "Friends getaway",
"travel_date": "2015-06",
"text": "Stay 3days 2 nights. Not able to connect to wifi half the time. Tv reception is bad. They turn off the power at 1100hrs sharp even when we paid for the late check out fee of rm15. Had to go down and...",
"user": {
"username": "Shnhzk T",
"user_location": {
"name": null,
"id": null
}
},
"title": "Most disguesting budget hotel i ever stayed"
},
{
"id": "280113859",
"lang": "en",
"location_id": "1770042",
"published_date": "2015-06-14T10:18:51-0400",
"rating": 4,
"helpful_votes": "0",
"rating_image_url": "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/s4.0-11068-5.png",
"url": "http://www.tripadvisor.com/ShowUserReviews-g298278-d1770042-r280113859-Tune_Hotel_Danga_Bay-Johor_Bahru_Johor_Bahru_District_Johor.html#review280113859",
"trip_type": "Family",
"travel_date": "2014-07",
"text": "Just stay a night after such a tiring day in legoland. The place is easy to find and hotel can be easily spot from the roadside. Room is as always relatively small but very clean. We really enjoy our...",
"user": {
"username": "feltroneu",
"user_location": {
"name": "Georgetown, Malaysia",
"id": null
}
},
"title": "Small but Clean and affordable"
}
],
"write_review": "http://www.tripadvisor.com/UserReview-g298278-d1770042-m11068-Tune_Hotel_Danga_Bay-Johor_Bahru_Johor_Bahru_District_Johor.html",
"ancestors": [
{
"abbrv": null,
"level": "City",
"name": "Johor Bahru",
"location_id": "298278"
},
{
"abbrv": null,
"level": "District",
"name": "Johor Bahru District",
"location_id": "2301796"
},
{
"abbrv": null,
"level": "State",
"name": "Johor",
"location_id": "298277"
},
{
"abbrv": null,
"level": "Country",
"name": "Malaysia",
"location_id": "293951"
}
],
"longitude": "103.71706",
"percent_recommended": null,
"review_rating_count": {
"1": "21",
"2": "26",
"3": "127",
"4": "306",
"5": "220"
},
"subratings": [
{
"rating_image_url": "http://static.tacdn.com/img2/ratings/traveler/ss4.0.gif",
"name": "rate_sleep",
"value": "4.0",
"localized_name": "Sleep Quality"
},
{
"rating_image_url": "http://static.tacdn.com/img2/ratings/traveler/ss3.5.gif",
"name": "rate_location",
"value": "3.5",
"localized_name": "Location"
},
{
"rating_image_url": "http://static.tacdn.com/img2/ratings/traveler/ss4.0.gif",
"name": "rate_room",
"value": "4.0",
"localized_name": "Rooms"
},
{
"rating_image_url": "http://static.tacdn.com/img2/ratings/traveler/ss4.0.gif",
"name": "rate_service",
"value": "4.0",
"localized_name": "Service"
},
{
"rating_image_url": "http://static.tacdn.com/img2/ratings/traveler/ss4.5.gif",
"name": "rate_value",
"value": "4.5",
"localized_name": "Value"
},
{
"rating_image_url": "http://static.tacdn.com/img2/ratings/traveler/ss4.0.gif",
"name": "rate_cleanliness",
"value": "4.0",
"localized_name": "Cleanliness"
}
],
"ranking_data": {
"ranking_string": "#6 of 82 hotels in Johor Bahru",
"ranking_out_of": "82",
"geo_location_id": "298278",
"ranking": "6",
"geo_location_name": "Johor Bahru"
},
"photo_count": "294",
"location_string": "Johor Bahru, Johor Bahru District, Johor",
"web_url": "http://www.tripadvisor.com/Hotel_Review-g298278-d1770042-Reviews-m11068-Tune_Hotel_Danga_Bay-Johor_Bahru_Johor_Bahru_District_Johor.html",
"price_level": "$",
"rating_image_url": "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/4.0-11068-5.png",
"awards": [
{
"award_type": "Traveler's Choice",
"year": "2015",
"images": {
"tiny": "http://www.tripadvisor.com/img/cdsi/img2/awards/tchotel_tiny-11068-5.png",
"small": "http://www.tripadvisor.com/img/cdsi/img2/awards/tchotel_2015_L_R-11068-5.jpg",
"large": "http://www.tripadvisor.com/img/cdsi/img2/awards/TC_2015_downloadable_L_R-11068-5.jpg"
},
"categories": [
"Bargain"
],
"display_name": "Traveler's Choice"
}
],
"name": "Tune Hotel Danga Bay",
"num_reviews": "700",
"category": {
"name": "hotel",
"localized_name": "Hotel"
},
"subcategory": [
{
"name": "hotel",
"localized_name": "Hotel"
}
],
"see_all_photos": "http://www.tripadvisor.com/Hotel_Review-g298278-d1770042-m11068-Reviews-Tune_Hotel_Danga_Bay-Johor_Bahru_Johor_Bahru_District_Johor.html#photos"
}

C# Class

 public class AddressObj  
{
public string street1 { get; set; }
public string street2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string country { get; set; }
public string postalcode { get; set; }
public string address_string { get; set; }
}
public class TripType
{
public string name { get; set; }
public string value { get; set; }
public string localized_name { get; set; }
}
public class UserLocation
{
public string name { get; set; }
public object id { get; set; }
}
public class User
{
public string username { get; set; }
public UserLocation user_location { get; set; }
}
public class Review
{
public string id { get; set; }
public string lang { get; set; }
public string location_id { get; set; }
public string published_date { get; set; }
public int rating { get; set; }
public string helpful_votes { get; set; }
public string rating_image_url { get; set; }
public string url { get; set; }
public string trip_type { get; set; }
public string travel_date { get; set; }
public string text { get; set; }
public User user { get; set; }
public string title { get; set; }
}
public class Ancestor
{
public object abbrv { get; set; }
public string level { get; set; }
public string name { get; set; }
public string location_id { get; set; }
}
public class ReviewRatingCount
{
public string __invalid_name__1 { get; set; }
public string __invalid_name__2 { get; set; }
public string __invalid_name__3 { get; set; }
public string __invalid_name__4 { get; set; }
public string __invalid_name__5 { get; set; }
}
public class Subrating
{
public string rating_image_url { get; set; }
public string name { get; set; }
public string value { get; set; }
public string localized_name { get; set; }
}
public class RankingData
{
public string ranking_string { get; set; }
public string ranking_out_of { get; set; }
public string geo_location_id { get; set; }
public string ranking { get; set; }
public string geo_location_name { get; set; }
}
public class Images
{
public string tiny { get; set; }
public string small { get; set; }
public string large { get; set; }
}
public class Award
{
public string award_type { get; set; }
public string year { get; set; }
public Images images { get; set; }
public List<string> categories { get; set; }
public string display_name { get; set; }
}
public class Category
{
public string name { get; set; }
public string localized_name { get; set; }
}
public class Subcategory
{
public string name { get; set; }
public string localized_name { get; set; }
}
public class RootObject
{
public AddressObj address_obj { get; set; }
public string latitude { get; set; }
public string rating { get; set; }
public string description { get; set; }
public string location_id { get; set; }
public List<TripType> trip_types { get; set; }
public List<Review> reviews { get; set; }
public string write_review { get; set; }
public List<Ancestor> ancestors { get; set; }
public string longitude { get; set; }
public object percent_recommended { get; set; }
public ReviewRatingCount review_rating_count { get; set; }
public List<Subrating> subratings { get; set; }
public RankingData ranking_data { get; set; }
public string photo_count { get; set; }
public string location_string { get; set; }
public string web_url { get; set; }
public string price_level { get; set; }
public string rating_image_url { get; set; }
public List<Award> awards { get; set; }
public string name { get; set; }
public string num_reviews { get; set; }
public Category category { get; set; }
public List<Subcategory> subcategory { get; set; }
public string see_all_photos { get; set; }
}

Popular posts from this blog

How to create zip file to download in JSP- Servlet

How to create DataGrid or GridView in JSP - Servlet

Pinging in ASP.NET Example