System.NullReferenceException: "Ссылка на объект не указывает на экземпляр объекта
Я хочу взять только id, medicareNumber и ogrn. Но говорит что: System.NullReferenceException: "Ссылка на объект не указывает на экземпляр объекта."
WSDLTest.PracticeLocation.identification.get вернул null.
Что я делаю не так?
class PracticeLocation
{
public Identification identification { get; set; }
}
class Identification
{
public int Id { get; set; }
public int MedicareNumber { get; set; }
public int Ogrn { get; set; }
}
PracticeLocation practiceLocation = JsonConvert
.DeserializeObject<PracticeLocation>(result.RequestMessage);
Console.WriteLine(
"Temperature in {0}: {1} C and {2}",
practiceLocation.identification.Id,
practiceLocation.identification.MedicareNumber,
practiceLocation.identification.Ogrn);`
result.RequestMessage:
{
"practiceLocation":{
"identification":{
"id":"101",
"medicareNumber":"101",
"ogrn":"1681745",
"okato":null,
"okpo":null
},
"businessName":"Городская клиническая больница №1 г. . Поликлиника №1",
"licence":{
"licenceNumber":"ЛО-31-01-70",
"licenceStartDate":"2019-02-08 00:00:00",
"licenceEndDate":null,
"licenceAdministrator":"Бюджетное учреждение"
},
"address":{
"kladrCode":null,
"addressText":" область, г. , проспект, 95а",
"postalCode":"308"
},
"communicationNumbers":{
"primaryTelephone":{
"number":"+747222",
"extension":null,
"supportsSMS":null
},
"electronicMail":[
],
"otherTelephone":[
]
}
},
"softwareInformation":null
}
Ответы (1 шт):
Автор решения: somik bGh
→ Ссылка
Просто неправильно классы создал:
public class Identification
{
public string id { get; set; }
public string medicareNumber { get; set; }
public string ogrn { get; set; }
}
public class Licence
{
public string licenceNumber { get; set; }
public string licenceStartDate { get; set; }
public object licenceEndDate { get; set; }
public string licenceAdministrator { get; set; }
}
public class Address
{
public object kladrCode { get; set; }
public string addressText { get; set; }
public string postalCode { get; set; }
}
public class PrimaryTelephone
{
public string number { get; set; }
public object extension { get; set; }
public object supportsSMS { get; set; }
}
public class CommunicationNumbers
{
public PrimaryTelephone primaryTelephone { get; set; }
public List<object> electronicMail { get; set; }
public List<object> otherTelephone { get; set; }
}
public class PracticeLocation
{
public Identification identification { get; set; }
public string businessName { get; set; }
public Licence licence { get; set; }
public Address address { get; set; }
public CommunicationNumbers communicationNumbers { get; set; }
}
public class Root
{
public PracticeLocation practiceLocation { get; set; }
}