Json Deserialization | Cannot Deserialize Current Json - c#

I have below Json -
{"property_id":"53863730","name":"Hayat Elhamra","address":{"line_1":"Jeddah","city":"Jeddah","state_province_name":"Jeddah","postal_code":"23212","country_code":"SA","obfuscation_required":false,"localized":{"links":{"ar-SA":{"method":"GET","href":"https://api.ean.com/2.4/properties/content?language=ar-SA&property_id=53863730&include=address"}}}},"location":{"coordinates":{"latitude":21.520902,"longitude":39.158265}},"phone":"20-01145772035","category":{"id":"16","name":"Apartment"},"rank":99999999,"business_model":{"expedia_collect":true,"property_collect":true},"dates":{"added":"2020-06-10T23:03:21.345Z","updated":"2020-06-10T23:03:23.701Z"},"chain":{"id":"0","name":"Independent"},"brand":{"id":"0","name":"Independent"}}
{"property_id":"53183065","name":"Carefully Furnished Bungalow With 2 Bathrooms, 7km From Pula","address":{"line_1":"1 x M 90,3","line_2":"PRIVATE_VACATION_HOME 3","city":"Fazana","state_province_name":"Istria (county)","postal_code":"52212","country_code":"HR","obfuscation_required":true,"localized":{"links":{"hr-HR":{"method":"GET","href":"https://api.ean.com/2.4/properties/content?language=hr-HR&property_id=53183065&include=address"}}}},"ratings":{"property":{"rating":"3.0","type":"Star"}},"location":{"coordinates":{"latitude":44.93,"longitude":13.8}},"phone":"410442743080","category":{"id":"17","name":"Private vacation home"},"rank":99999999,"business_model":{"expedia_collect":true,"property_collect":false},"dates":{"added":"2020-05-13T21:06:42.861Z","updated":"2020-05-18T21:57:39.242Z"},"statistics":{"1073743378":{"id":"1073743378","name":"Number of bedrooms - 2","value":"2"},"1073743380":{"id":"1073743380","name":"Max occupancy - 4","value":"4"},"1073743379":{"id":"1073743379","name":"Number of bathrooms - 2","value":"2"}},"chain":{"id":"7278","name":"Belvilla"},"brand":{"id":"7353","name":"Belvilla"}}
{"property_id":"53182898","name":"Snug Cottage in Pašman With Roofed Terrace","address":{"line_1":"Pasman","city":"Pasman","state_province_name":"Zadar","postal_code":"23260","country_code":"HR","obfuscation_required":true,"localized":{"links":{"hr-HR":{"method":"GET","href":"https://api.ean.com/2.4/properties/content?language=hr-HR&property_id=53182898&include=address"}}}},"ratings":{"property":{"rating":"1.0","type":"Star"}},"location":{"coordinates":{"latitude":43.891571,"longitude":15.423619}},"phone":"410442743080","category":{"id":"11","name":"Cottage"},"rank":99999999,"business_model":{"expedia_collect":true,"property_collect":false},"dates":{"added":"2020-05-13T21:13:49.155Z","updated":"2020-05-27T21:02:31.808Z"},"statistics":{"1073743378":{"id":"1073743378","name":"Number of bedrooms - 2","value":"2"},"1073743380":{"id":"1073743380","name":"Max occupancy - 5","value":"5"},"1073743379":{"id":"1073743379","name":"Number of bathrooms - 1","value":"1"}},"chain":{"id":"7278","name":"Belvilla"},"brand":{"id":"7353","name":"Belvilla"}}
For this I have created below class structure -
public class Property
{
public string property_id { get; set; }
public string name { get; set; }
public Address address { get; set; }
public Location location { get; set; }
public string phone { get; set; }
public Category category { get; set; }
public int rank { get; set; }
public Business_Model business_model { get; set; }
public Dates dates { get; set; }
public Chain chain { get; set; }
public Brand brand { get; set; }
}
public class Address
{
public string line_1 { get; set; }
public string city { get; set; }
public string state_province_name { get; set; }
public string postal_code { get; set; }
public string country_code { get; set; }
public bool obfuscation_required { get; set; }
public Localized localized { get; set; }
}
public class Localized
{
public Links links { get; set; }
}
public class Links
{
public ArSA arSA { get; set; }
}
public class ArSA
{
public string method { get; set; }
public string href { get; set; }
}
public class Location
{
public Coordinates coordinates { get; set; }
}
public class Coordinates
{
public float latitude { get; set; }
public float longitude { get; set; }
}
public class Category
{
public string id { get; set; }
public string name { get; set; }
}
public class Business_Model
{
public bool expedia_collect { get; set; }
public bool property_collect { get; set; }
}
public class Dates
{
public DateTime added { get; set; }
public DateTime updated { get; set; }
}
public class Chain
{
public string id { get; set; }
public string name { get; set; }
}
public class Brand
{
public string id { get; set; }
public string name { get; set; }
}
I have below code where I am getting error -
using (StreamReader streamReader = new StreamReader("d://propertycontent.expediacollect.en-US.json"))
{
using (var json = new JsonTextReader(streamReader))
{
JsonSerializer serializer = new JsonSerializer();
var properties= (List<Property>)serializer.Deserialize(json, typeof(List<Property>));
}
}
Error -
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Property]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'property_id', line 1, position 15.'

It is not deserializing because it is not valid json. To make it valid, and to make it a List<Property> add [ to the beginning of the json and ] to the end of the json. Just enclose the json in [ ... ] to make it valid and it will deserialize assuming the rest of it is valid and is not missing any commas or brackets.

try this, you will have to install NewtonsoftJson. It was tested using Visual Studio and Postman and works properly.
var jsonOrig= ...your json
var json = JsonConvert.SerializeObject(jsonOrig);
var jsonObj = JsonConvert.DeserializeObject<DataRoot>(json);
classes
public class DataRoot
{
public string property_id { get; set; }
public string name { get; set; }
public Address address { get; set; }
public Location location { get; set; }
public string phone { get; set; }
public Category category { get; set; }
public int rank { get; set; }
public BusinessModel business_model { get; set; }
public Dates dates { get; set; }
public Chain chain { get; set; }
public Brand brand { get; set; }
}
public class ArSA
{
public string method { get; set; }
public string href { get; set; }
}
public class Links
{
[JsonProperty("ar-SA")]
public ArSA ArSA { get; set; }
}
public class Localized
{
public Links links { get; set; }
}
public class Address
{
public string line_1 { get; set; }
public string city { get; set; }
public string state_province_name { get; set; }
public string postal_code { get; set; }
public string country_code { get; set; }
public bool obfuscation_required { get; set; }
public Localized localized { get; set; }
}
public class Coordinates
{
public double latitude { get; set; }
public double longitude { get; set; }
}
public class Location
{
public Coordinates coordinates { get; set; }
}
public class Category
{
public string id { get; set; }
public string name { get; set; }
}
public class BusinessModel
{
public bool expedia_collect { get; set; }
public bool property_collect { get; set; }
}
public class Dates
{
public DateTime added { get; set; }
public DateTime updated { get; set; }
}
public class Chain
{
public string id { get; set; }
public string name { get; set; }
}
public class Brand
{
public string id { get; set; }
public string name { get; set; }
}
`````

Related

Crestron Deserialize in C# and send array to Simpl+

Trying best how to take the following classes and deserialize a Json file to return each class values back to Simpl+. I am able to receive the Total value but anything in a list I am at a lost.
public class Client
{
public string clientId { get; set; }
public string locale { get; set; }
public string location { get; set; }
public string auxiliaryId { get; set; }
public string description { get; set; }
public string type { get; set; }
public string typeDescription { get; set; }
public Hardware hardware { get; set; }
public Network network { get; set; }
}
public class Hardware
{
public string type { get; set; }
public string softwareVersion { get; set; }
public string serialNumber { get; set; }
public string hardwareVersion { get; set; }
public string model { get; set; }
}
public class Network
{
public string ip { get; set; }
public string mac { get; set; }
public object homepage { get; set; }
public string dhcpSubnet { get; set; }
}
public class Result
{
public List<Client> clients { get; set; }
public string total { get; set; }
public int limit { get; set; }
public int page { get; set; }
}
public class Root
{
public string jsonrpc { get; set; }
public object id { get; set; }
public Result result { get; set; }
}
I was able to resolve this by adding the following to the foreach statement:
args.MyIndex = (ushort)(rootObject.TriplePlayResult.clients.IndexOf(item) + 1);

Cannot deserialize the current JSON object into type because the type requires a JSON array

I am new to JSON string handling in C# and have the following error when trying to deserialize a JSON string:
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Formula1Info.Models.clsMRData]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'MRData.xmlns', line 1, position 19.
The JSON string is:
{"MRData":{"xmlns":"http:\/\/ergast.com\/mrd\/1.5","series":"f1","url":"http://ergast.com/api/f1/1952.json","limit":"30","offset":"0","total":"8","RaceTable":{"season":"1952","Races":[{"season":"1952","round":"1","url":"http:\/\/en.wikipedia.org\/wiki\/1952_Swiss_Grand_Prix","raceName":"Swiss Grand Prix","Circuit":{"circuitId":"bremgarten","url":"http:\/\/en.wikipedia.org\/wiki\/Circuit_Bremgarten","circuitName":"Circuit Bremgarten","Location":{"lat":"46.9589","long":"7.40194","locality":"Bern","country":"Switzerland"}},"date":"1952-05-18"},{"season":"1952","round":"2","url":"http:\/\/en.wikipedia.org\/wiki\/1952_Indianapolis_500","raceName":"Indianapolis 500","Circuit":{"circuitId":"indianapolis","url":"http:\/\/en.wikipedia.org\/wiki\/Indianapolis_Motor_Speedway","circuitName":"Indianapolis Motor Speedway","Location":{"lat":"39.795","long":"-86.2347","locality":"Indianapolis","country":"USA"}},"date":"1952-05-30"},{"season":"1952","round":"3","url":"http:\/\/en.wikipedia.org\/wiki\/1952_Belgian_Grand_Prix","raceName":"Belgian Grand Prix","Circuit":{"circuitId":"spa","url":"http:\/\/en.wikipedia.org\/wiki\/Circuit_de_Spa-Francorchamps","circuitName":"Circuit de Spa-Francorchamps","Location":{"lat":"50.4372","long":"5.97139","locality":"Spa","country":"Belgium"}},"date":"1952-06-22"},{"season":"1952","round":"4","url":"http:\/\/en.wikipedia.org\/wiki\/1952_French_Grand_Prix","raceName":"French Grand Prix","Circuit":{"circuitId":"essarts","url":"http:\/\/en.wikipedia.org\/wiki\/Rouen-Les-Essarts","circuitName":"Rouen-Les-Essarts","Location":{"lat":"49.3306","long":"1.00458","locality":"Rouen","country":"France"}},"date":"1952-07-06"},{"season":"1952","round":"5","url":"http:\/\/en.wikipedia.org\/wiki\/1952_British_Grand_Prix","raceName":"British Grand Prix","Circuit":{"circuitId":"silverstone","url":"http:\/\/en.wikipedia.org\/wiki\/Silverstone_Circuit","circuitName":"Silverstone Circuit","Location":{"lat":"52.0786","long":"-1.01694","locality":"Silverstone","country":"UK"}},"date":"1952-07-19"},{"season":"1952","round":"6","url":"http:\/\/en.wikipedia.org\/wiki\/1952_German_Grand_Prix","raceName":"German Grand Prix","Circuit":{"circuitId":"nurburgring","url":"http:\/\/en.wikipedia.org\/wiki\/N%C3%BCrburgring","circuitName":"Nürburgring","Location":{"lat":"50.3356","long":"6.9475","locality":"Nürburg","country":"Germany"}},"date":"1952-08-03"},{"season":"1952","round":"7","url":"http:\/\/en.wikipedia.org\/wiki\/1952_Dutch_Grand_Prix","raceName":"Dutch Grand Prix","Circuit":{"circuitId":"zandvoort","url":"http:\/\/en.wikipedia.org\/wiki\/Circuit_Zandvoort","circuitName":"Circuit Park Zandvoort","Location":{"lat":"52.3888","long":"4.54092","locality":"Zandvoort","country":"Netherlands"}},"date":"1952-08-17"},{"season":"1952","round":"8","url":"http:\/\/en.wikipedia.org\/wiki\/1952_Italian_Grand_Prix","raceName":"Italian Grand Prix","Circuit":{"circuitId":"monza","url":"http:\/\/en.wikipedia.org\/wiki\/Autodromo_Nazionale_Monza","circuitName":"Autodromo Nazionale di Monza","Location":{"lat":"45.6156","long":"9.28111","locality":"Monza","country":"Italy"}},"date":"1952-09-07"}]}}}
and I deserialize this via this code:
var jF1Season = JsonConvert.DeserializeObject<Root>(strJSON);
The class structure is:
public class Root
{
public List<clsMRData> MRData { get; set; }
}
public class clsMRData
{
public string xmlns { get; set; }
public string series { get; set; }
public string url { get; set; }
public string limit { get; set; }
public string offset { get; set; }
public string total { get; set; }
public List<clsRaceTable> RaceTable { get; set; }
}
public class clsRaceTable
{
public string season { get; set; }
public List<clsRace> Races { get; set; }
}
public class clsRace
{
public string season { get; set; }
public string round { get; set; }
public string url { get; set; }
public string raceName { get; set; }
public List<clsCircuit> Circuit { get; set; }
public string date { get; set; }
public string time { get; set; }
}
public class clsCircuit
{
public string circuitId { get; set; }
public string url { get; set; }
public string circuitName { get; set; }
public List<clsLocation> Location { get; set; }
}
public class clsLocation
{
public string lat { get; set; }
[JsonProperty(PropertyName = "Root.MRData.RaceTable.Races.Circuit.Location.long")]
public string lon { get; set; }
public string locality { get; set; }
public string country { get; set; }
}
I guess the error is relating to how I have set this structure up, but cannot see why, so any help in solving this error would be appreciated.
you have several bugs in your code.Replace List<clsRaceTable> , List<clsCircuit> , List<clsLocation> with clsRaceTable,clsCircuit and clsLocation. Your classes should be
public class Root
{
public clsMRData MRData { get; set; }
}
public class clsMRData
{
public string xmlns { get; set; }
public string series { get; set; }
public string url { get; set; }
public string limit { get; set; }
public string offset { get; set; }
public string total { get; set; }
public clsRaceTable RaceTable { get; set; }
}
public class clsRaceTable
{
public string season { get; set; }
public List<clsRace> Races { get; set; }
}
public class clsRace
{
public string season { get; set; }
public string round { get; set; }
public string url { get; set; }
public string raceName { get; set; }
public clsCircuit Circuit { get; set; }
public string date { get; set; }
public string time { get; set; }
}
public class clsCircuit
{
public string circuitId { get; set; }
public string url { get; set; }
public string circuitName { get; set; }
public clsLocation Location { get; set; }
}
public class clsLocation
{
public string lat { get; set; }
[JsonProperty(PropertyName = "long")]
public string lon { get; set; }
public string locality { get; set; }
public string country { get; set; }
}

How to remove $ for json result?

I am trying to read a cell value from a simple google sheet
https://docs.google.com/spreadsheets/d/1opP1t_E9xfuLXBkhuyzo5j9k_xBNDx0XKb31JwLP1MM/edit?usp=sharing
then I published it and I get an API link that return JSON, check the following
https://spreadsheets.google.com/feeds/list/1opP1t_E9xfuLXBkhuyzo5j9k_xBNDx0XKb31JwLP1MM/1/public/values?alt=json
when I tried to generate C# classes from JSON using http://json2csharp.com/, I get
invalid_name and $ (which is not fine for csharp compiler)
public class Id
{
public string __invalid_name__$t { get; set; }
}
public class Updated
{
public DateTime __invalid_name__$t { get; set; }
}
public class Category
{
public string scheme { get; set; }
public string term { get; set; }
}
public class Title
{
public string type { get; set; }
public string __invalid_name__$t { get; set; }
}
public class Link
{
public string rel { get; set; }
public string type { get; set; }
public string href { get; set; }
}
public class Name
{
public string __invalid_name__$t { get; set; }
}
public class Email
{
public string __invalid_name__$t { get; set; }
}
public class Author
{
public Name name { get; set; }
public Email email { get; set; }
}
public class OpenSearchTotalResults
{
public string __invalid_name__$t { get; set; }
}
public class OpenSearchStartIndex
{
public string __invalid_name__$t { get; set; }
}
public class Id2
{
public string __invalid_name__$t { get; set; }
}
public class Updated2
{
public DateTime __invalid_name__$t { get; set; }
}
public class Category2
{
public string scheme { get; set; }
public string term { get; set; }
}
public class Title2
{
public string type { get; set; }
public string __invalid_name__$t { get; set; }
}
public class Content
{
public string type { get; set; }
public string __invalid_name__$t { get; set; }
}
public class Link2
{
public string rel { get; set; }
public string type { get; set; }
public string href { get; set; }
}
public class GsxName
{
public string __invalid_name__$t { get; set; }
}
public class GsxPhonenumber
{
public string __invalid_name__$t { get; set; }
}
public class Entry
{
public Id2 id { get; set; }
public Updated2 updated { get; set; }
public List<Category2> category { get; set; }
public Title2 title { get; set; }
public Content content { get; set; }
public List<Link2> link { get; set; }
public GsxName __invalid_name__gsx$name { get; set; }
public GsxPhonenumber __invalid_name__gsx$phonenumber { get; set; }
}
public class Feed
{
public string xmlns { get; set; }
public string __invalid_name__xmlns$openSearch { get; set; }
public string __invalid_name__xmlns$gsx { get; set; }
public Id id { get; set; }
public Updated updated { get; set; }
public List<Category> category { get; set; }
public Title title { get; set; }
public List<Link> link { get; set; }
public List<Author> author { get; set; }
public OpenSearchTotalResults __invalid_name__openSearch$totalResults { get; set; }
public OpenSearchStartIndex __invalid_name__openSearch$startIndex { get; set; }
public List<Entry> entry { get; set; }
}
public class RootObject
{
public string version { get; set; }
public string encoding { get; set; }
public Feed feed { get; set; }
}
I want to serialize and deserialize this class, also i want to remove $,what i need to do?
Obviously json2csharp converts each json object into a class and converts the key names into variable names literally. So whenever it finds a key name starting with $ it can't create a c# variable with this character and it precedes the variable name with a _invalid_name_. There is nothing wrong here.
You should tell why do you want to remove this invalid_name phrase from variable name? do you want to serialize and deserialize this class? If so you could use NewtonSoft Json library and define those fields with $ sign like this:
[JsonProperty(PropertyName = "$t")]
public string t { get; set; }
this will allow you to serialize/deserialize the json doc
same for gsx$name:
[JsonProperty(PropertyName = "gsx$name")]
public string gsxname { get; set; }

Cannot deserialize the current JSON object - Null List

I am using Newtonsoft.JSON in C# and I have JSON like this:
http://woothemes.github.io/woocommerce/rest-api/#get-orders
Note:
coupon_lines []
When I serialize the JSON, I get this error:
List<Order> result = JObject.Parse(GetJson(url))["orders"].ToObject<List<Order>>();
Here is the coupon json:
"coupon_lines":{"id":65,"code":"alank10","amount":"33.08"}
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[WooCommerce.Core.Models.CouponLine]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
How do I serialize coupon_lines to List
public class CouponLine
{
public int id { get; set; }
public string code { get; set; }
public decimal amount { get; set; }
}
Here is my class:
public class CouponLines
{
public List<CouponLine> lines { get; set; }
}
public class Order
{
public int id { get; set; }
public string order_number { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
public DateTime completed_at { get; set; }
public string status { get; set; }
public string currency { get; set; }
public decimal total { get; set; }
public decimal subtotal { get; set; }
public int total_line_items_quantity { get; set; }
public decimal total_tax { get; set; }
public decimal total_shipping { get; set; }
public decimal cart_tax { get; set; }
public decimal shipping_tax { get; set; }
public decimal total_discount { get; set; }
public decimal cart_discount { get; set; }
public decimal order_discount { get; set; }
public string shipping_methods { get; set; }
public PaymentDetails payment_details { get; set; }
public BillingAddress billing_address { get; set; }
public ShippingAddress shipping_address { get; set; }
public string note { get; set; }
public string customer_ip { get; set; }
public string customer_user_agent { get; set; }
public string customer_id { get; set; }
public string view_order_url { get; set; }
public List<LineItem> line_items { get; set; }
public List<ShippingLine> shipping_lines { get; set; }
//public List<object> tax_lines { get; set; }
//public List<object> fee_lines { get; set; }
public CouponLines coupon_lines { get; set; }
public Customer customer { get; set; }
}
You should use some kind of "root" object that contains this list, for example:
var parsedResponse = JsonConvert.DeserializeObject<CouponLines>(jsonResponse);
//...
public class CouponLines
{
public List<CouponLine> order { get; set; }
}
The string from your example
"coupon_lines":{"id":65,"code":"alank10","amount":"33.08"}
is invalid JSON: to make it valid add { at the beginning and } at the end:
{"coupon_lines":{"id":65,"code":"alank10","amount":"33.08"}}
Also, you said, you want to deserialize list, and you do not have list in your example. To get list your JSON object should contain list of objects (even if there is one object) in square breckets []:
{
"coupon_lines":[
{
"id":65,
"code":"alank10",
"amount":"33.08"
}
//if you have several objects - put it here after comma:
//,
//{
// "id":100500,
// "code":"somecode",
// "amount":"33.08"
//}
]
}
I had a similar problem (and also similar reuqest with orders, lines, shippings etc...)
first thing is that:
in your json, you can receive your list as
"line_items" : null
without any problems
or also this one:
"line_items" : []
does the trick.
but if you want the perfect solution, so you can avoid to send the line_items parameter completely, the solution is pretty easy,
just decorate your property on the request with
[JsonProperty(Required = Required.AllowNull)]
public List<LineItem> line_items { get; set; }
it worked perfectly for me.

Could not cast or convert from {null} to system.Int32 in JSON response C#

I'm getting the following exception when using this bit of code to deserialize a JSON response from CrunchBase. The weird thing is it only happens to certain pages that are being deserialized even though both the results that work fine and the ones that don't both have empty [], empty"", and null values in key:value pairs. How can I cast or correct my mistake?
Exception gets thrown here:
JsonSerializer serializer = new JsonSerializer();
RootObject ro = JsonConvert.DeserializeObject<RootObject>(response);
The inner exception is:
InnerException:
Message=Could not cast or convert from {null} to System.Int32.
Source=Newtonsoft.Json
Thanks for your eyes in advance!
Update:
as asked for the structure of the root object and the additional objects on that JSON endpoint. These were generated by http://json2csharp.com/ after putting the URL of the JSON endpoint into it.
The JSON is long so here are two example links: this one works without error http://api.crunchbase.com/v/1/company/kiip.js , while this other (and others) throws the exception http://api.crunchbase.com/v/1/company/tata-communications.js
public class Image
{
public List<List<object>> available_sizes { get; set; }
public object attribution { get; set; }
}
public class Person
{
public string first_name { get; set; }
public string last_name { get; set; }
public string permalink { get; set; }
}
public class Relationship
{
public bool is_past { get; set; }
public string title { get; set; }
public Person person { get; set; }
}
public class Provider
{
public string name { get; set; }
public string permalink { get; set; }
}
public class Providership
{
public string title { get; set; }
public bool is_past { get; set; }
public Provider provider { get; set; }
}
public class FinancialOrg
{
public string name { get; set; }
public string permalink { get; set; }
}
public class Person2
{
public string first_name { get; set; }
public string last_name { get; set; }
public string permalink { get; set; }
}
public class Investment
{
public object company { get; set; }
public FinancialOrg financial_org { get; set; }
public Person2 person { get; set; }
}
public class FundingRound
{
public string round_code { get; set; }
public string source_url { get; set; }
public string source_description { get; set; }
public double raised_amount { get; set; }
public string raised_currency_code { get; set; }
public int funded_year { get; set; }
public int funded_month { get; set; }
public int funded_day { get; set; }
public List<Investment> investments { get; set; }
}
public class Office
{
public string description { get; set; }
public string address1 { get; set; }
public string address2 { get; set; }
public string zip_code { get; set; }
public string city { get; set; }
public string state_code { get; set; }
public string country_code { get; set; }
public object latitude { get; set; }
public object longitude { get; set; }
}
public class VideoEmbed
{
public string embed_code { get; set; }
public string description { get; set; }
}
public class Screenshot
{
public List<List<object>> available_sizes { get; set; }
public object attribution { get; set; }
}
public class RootObject
{
public string name { get; set; }
public string permalink { get; set; }
public string crunchbase_url { get; set; }
public string homepage_url { get; set; }
public string blog_url { get; set; }
public string blog_feed_url { get; set; }
public string twitter_username { get; set; }
public string category_code { get; set; }
public int number_of_employees { get; set; }
public int founded_year { get; set; }
public int founded_month { get; set; }
public object founded_day { get; set; }
public object deadpooled_year { get; set; }
public object deadpooled_month { get; set; }
public object deadpooled_day { get; set; }
public object deadpooled_url { get; set; }
public string tag_list { get; set; }
public string alias_list { get; set; }
public string email_address { get; set; }
public string phone_number { get; set; }
public string description { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
public string overview { get; set; }
public Image image { get; set; }
public List<object> products { get; set; }
public List<Relationship> relationships { get; set; }
public List<object> competitions { get; set; }
public List<Providership> providerships { get; set; }
public string total_money_raised { get; set; }
public List<FundingRound> funding_rounds { get; set; }
public List<object> investments { get; set; }
public object acquisition { get; set; }
public List<object> acquisitions { get; set; }
public List<Office> offices { get; set; }
public List<object> milestones { get; set; }
public object ipo { get; set; }
public List<VideoEmbed> video_embeds { get; set; }
public List<Screenshot> screenshots { get; set; }
public List<object> external_links { get; set; }
}
Json.NET supports JSON Schema. You could create a schema with all the required properties marked and validate incoming JSON against it before deserializing. In this you can check if value is null you can make change it to some default value.
Hope this works for you.

Categories

Resources