Deserializing complex JSON - c#

I am trying to deserialize this JSON:
{
"request": {
"Target": "Affiliate",
"Format": "json",
"Service": "HasOffers",
"Version": "2",
"NetworkToken": "NETVTxpCN4QxoWuE6D6SCdh67itLvG",
"Method": "getSignupAnswers",
"id": "9820",
"__lc_visitor_id_1040387": "S1501672650.ef9130f70a",
"optimizelyEndUserId": "oeu1504526823197r0.9821082007049919",
"optimizelySegments": "{\"3005961667\":\"campaign\",\"3007971800\":\"gc\",\"3016921538\":\"false\"}",
"optimizelyBuckets": "{\"8910731217\":\"8900223657\"}",
"_mkto_trk": "id:210-BFY-977&token:_mch-hasoffers.com-1504526823819-68924",
"__gaTune": "GA1.2.1953499689.1501744456",
"_hp2_id_1318563364": "{\"userId\":null,\"pageviewId\":\"5080006815314464\",\"sessionId\":\"3328773167767995\",\"identity\":\"23255-2\",\"trackerVersion\":\"3.0\"}",
"intercom-session-zrjutp6m": "QXAxQTdza0JnNmVPLzNxZDFXSmFjbUQxRnVxQjArcmNmQWxMZzM4NWpSbWt3VXNzemFydG5oVjZYempaUlg3bS0tR0VrYWcwTGpSY3I4cDdsMFB3TndlUT09--5c9d563a96f41049f2703a3121484e9a299b4148",
"intercom-lou-zrjutp6m": "1"
},
"response": {
"status": 1,
"httpStatus": 200,
"data": {
"140768": {
"SignupAnswer": {
"id": "140768",
"question_id": "1",
"responder_type": "affiliate",
"answer": "Individual \r\n",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Affiliate Type",
"type": "affiliate",
"status": "active"
}
},
"140770": {
"SignupAnswer": {
"id": "140770",
"question_id": "3",
"responder_type": "affiliate",
"answer": "Rugved Agro",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Organisation Name",
"type": "affiliate",
"status": "active"
}
},
"140772": {
"SignupAnswer": {
"id": "140772",
"question_id": "5",
"responder_type": "affiliate",
"answer": "9822288117",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Contact Number ",
"type": "affiliate",
"status": "active"
}
},
"140774": {
"SignupAnswer": {
"id": "140774",
"question_id": "7",
"responder_type": "affiliate",
"answer": "7972274145",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Secondary Contact Number",
"type": "affiliate",
"status": "active"
}
},
"140776": {
"SignupAnswer": {
"id": "140776",
"question_id": "9",
"responder_type": "affiliate",
"answer": "",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Secondary E-mail Adress",
"type": "affiliate",
"status": "active"
}
},
"140778": {
"SignupAnswer": {
"id": "140778",
"question_id": "11",
"responder_type": "affiliate",
"answer": "SACHIN RAMLAL AGALE",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Payee Name",
"type": "affiliate",
"status": "active"
}
},
"140780": {
"SignupAnswer": {
"id": "140780",
"question_id": "13",
"responder_type": "affiliate",
"answer": "Electronic Fund Transfer \r\n",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Payment Mode",
"type": "affiliate",
"status": "active"
}
},
"140782": {
"SignupAnswer": {
"id": "140782",
"question_id": "15",
"responder_type": "affiliate",
"answer": "0480104000105996",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Bank Account Number",
"type": "affiliate",
"status": "active"
}
},
"140784": {
"SignupAnswer": {
"id": "140784",
"question_id": "17",
"responder_type": "affiliate",
"answer": "IDBI BANK ",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Bank Name",
"type": "affiliate",
"status": "active"
}
},
"140786": {
"SignupAnswer": {
"id": "140786",
"question_id": "19",
"responder_type": "affiliate",
"answer": "IBKL0000480",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "IFSC Code",
"type": "affiliate",
"status": "active"
}
},
"140788": {
"SignupAnswer": {
"id": "140788",
"question_id": "21",
"responder_type": "affiliate",
"answer": "431259006",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "MICR Code",
"type": "affiliate",
"status": "active"
}
},
"140790": {
"SignupAnswer": {
"id": "140790",
"question_id": "23",
"responder_type": "affiliate",
"answer": "Aurangabad ",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "Bank City",
"type": "affiliate",
"status": "active"
}
},
"140792": {
"SignupAnswer": {
"id": "140792",
"question_id": "25",
"responder_type": "affiliate",
"answer": "",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:23",
"question": "UPLOAD DOCUMENTS\u00a0(If required For Receiving Payments)",
"type": "affiliate",
"status": "deleted"
}
},
"140794": {
"SignupAnswer": {
"id": "140794",
"question_id": "27",
"responder_type": "affiliate",
"answer": "rugvedagro.blogspot.in",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:24",
"question": "Website URL",
"type": "affiliate",
"status": "active"
}
},
"140796": {
"SignupAnswer": {
"id": "140796",
"question_id": "29",
"responder_type": "affiliate",
"answer": "Blog\r\n",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:24",
"question": "Website Type",
"type": "affiliate",
"status": "active"
}
},
"140798": {
"SignupAnswer": {
"id": "140798",
"question_id": "31",
"responder_type": "affiliate",
"answer": "Btw 1000-10000\r\n",
"responder_user_id": null,
"ref_id": null,
"responder_id": "9820",
"modified": "2017-07-04 02:55:24",
"question": "Monthly Visits",
"type": "affiliate",
"status": "active"
}
}
},
"errors": [
],
"errorMessage": null
}
}
The classes I have are as follows:
public class Request
{
public string Target { get; set; }
public string Format { get; set; }
public string Service { get; set; }
public string Version { get; set; }
public string NetworkToken { get; set; }
public string Method { get; set; }
public string id { get; set; }
public string __lc_visitor_id_1040387 { get; set; }
public string optimizelyEndUserId { get; set; }
public string optimizelySegments { get; set; }
public string optimizelyBuckets { get; set; }
public string _mkto_trk { get; set; }
public string __gaTune { get; set; }
public string _hp2_id_1318563364 { get; set; }
[JsonProperty(PropertyName = "intercom-session-zrjutp6m")]
public string __invalid_name__intercom_session_zrjutp6m { get; set; }
[JsonProperty(PropertyName = "intercom-lou-zrjutp6m")]
public string __invalid_name__intercom_lou_zrjutp6m { get; set; }
}
public class SignupAnswer
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class Data
{
/* I can't code this class */
}
public class Response
{
public int status { get; set; }
public int httpStatus { get; set; }
public Data data { get; set; } //I can't code this class
public List<object> errors { get; set; }
public object errorMessage { get; set; }
}
public class RootObject
{
public Request request { get; set; }
public Response response { get; set; }
}
I have already tried it json2csharp. The problem here is the data under node response -> data is dynamic. So I cannot have a fixed class name

The Data Property of the Response Class should be a Dictionary:
public class Response
{
public int status { get; set; }
public int httpStatus { get; set; }
public Dictionary<string,Data> data { get; set; }
public object[] errors { get; set; }
public object errorMessage { get; set; }
}
probably you need another wrapper around signupanswer like this:
public class Data
{
public Signupanswer Signupanswer { get;set; }
}

I use the special paste option in Visual Studio:
I get this result:
public class Rootobject
{
public Request request { get; set; }
public Response response { get; set; }
}
public class Request
{
public string Target { get; set; }
public string Format { get; set; }
public string Service { get; set; }
public string Version { get; set; }
public string NetworkToken { get; set; }
public string Method { get; set; }
public string id { get; set; }
public string __lc_visitor_id_1040387 { get; set; }
public string optimizelyEndUserId { get; set; }
public string optimizelySegments { get; set; }
public string optimizelyBuckets { get; set; }
public string _mkto_trk { get; set; }
public string __gaTune { get; set; }
public string _hp2_id_1318563364 { get; set; }
public string intercomsessionzrjutp6m { get; set; }
public string intercomlouzrjutp6m { get; set; }
}
public class Response
{
public int status { get; set; }
public int httpStatus { get; set; }
public Data data { get; set; }
public object[] errors { get; set; }
public object errorMessage { get; set; }
}
public class Data
{
public _140768 _140768 { get; set; }
public _140770 _140770 { get; set; }
public _140772 _140772 { get; set; }
public _140774 _140774 { get; set; }
public _140776 _140776 { get; set; }
public _140778 _140778 { get; set; }
public _140780 _140780 { get; set; }
public _140782 _140782 { get; set; }
public _140784 _140784 { get; set; }
public _140786 _140786 { get; set; }
public _140788 _140788 { get; set; }
public _140790 _140790 { get; set; }
public _140792 _140792 { get; set; }
public _140794 _140794 { get; set; }
public _140796 _140796 { get; set; }
public _140798 _140798 { get; set; }
}
public class _140768
{
public Signupanswer SignupAnswer { get; set; }
}
public class Signupanswer
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140770
{
public Signupanswer1 SignupAnswer { get; set; }
}
public class Signupanswer1
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140772
{
public Signupanswer2 SignupAnswer { get; set; }
}
public class Signupanswer2
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140774
{
public Signupanswer3 SignupAnswer { get; set; }
}
public class Signupanswer3
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140776
{
public Signupanswer4 SignupAnswer { get; set; }
}
public class Signupanswer4
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140778
{
public Signupanswer5 SignupAnswer { get; set; }
}
public class Signupanswer5
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140780
{
public Signupanswer6 SignupAnswer { get; set; }
}
public class Signupanswer6
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140782
{
public Signupanswer7 SignupAnswer { get; set; }
}
public class Signupanswer7
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140784
{
public Signupanswer8 SignupAnswer { get; set; }
}
public class Signupanswer8
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140786
{
public Signupanswer9 SignupAnswer { get; set; }
}
public class Signupanswer9
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140788
{
public Signupanswer10 SignupAnswer { get; set; }
}
public class Signupanswer10
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140790
{
public Signupanswer11 SignupAnswer { get; set; }
}
public class Signupanswer11
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140792
{
public Signupanswer12 SignupAnswer { get; set; }
}
public class Signupanswer12
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140794
{
public Signupanswer13 SignupAnswer { get; set; }
}
public class Signupanswer13
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140796
{
public Signupanswer14 SignupAnswer { get; set; }
}
public class Signupanswer14
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}
public class _140798
{
public Signupanswer15 SignupAnswer { get; set; }
}
public class Signupanswer15
{
public string id { get; set; }
public string question_id { get; set; }
public string responder_type { get; set; }
public string answer { get; set; }
public object responder_user_id { get; set; }
public object ref_id { get; set; }
public string responder_id { get; set; }
public string modified { get; set; }
public string question { get; set; }
public string type { get; set; }
public string status { get; set; }
}

Related

Deserilizing Json Response of HttpClient using ASP.NET Core

I am calling a third-party API with HttpClient GET Request and it works fine. The response is quite complex of objects. All I want to do is to extract a specific attribute within these objects. Here is the response Json
"creationTime": "2021-11-06T12:22:49.602Z",
"currency": "USD",
"customer": {
"firstName": "xxxx"
},
"id": "xxxx",
"lastUpdatedTime": "2021-11-06T12:22:51.689Z",
"merchant": "xxx",
"merchantAmount": 33,
"merchantCategoryCode": "5311",
"merchantCurrency": "USD",
"reference": "XX",
"result": "SUCCESS",
"sourceOfFunds": {
"provided": {
"card": {
"brand": "MASTERCARD",
"expiry": {
"month": "X",
"year": "XX"
},
"fundingMethod": "DEBIT",
"nameOnCard": "XXX",
"number": "XXXXX123",
"scheme": "MASTERCARD",
"storedOnFile": "NOT_STORED"
}
},
"type": "CARD"
},
"status": "CAPTURED",
"totalAuthorizedAmount": 33,
"totalCapturedAmount": 33,
"totalRefundedAmount": 0,
"transaction": [
{
"3DSecure": {
"acsEci": "02",
"authenticationToken": "XXXX+XXXX=",
"paResStatus": "Y",
"veResEnrolled": "Y",
"xid": "mmmXXX"
},
"3DSecureId": "XXX",
"authorizationResponse": {
"cardSecurityCodeError": "M",
"commercialCardIndicator": "1",
"date": "1106",
"financialNetworkCode": "XX",
"financialNetworkDate": "2021-11-06",
"posData": "XXX",
"posEntryMode": "xxx",
"processingCode": "000000",
"responseCode": "00",
"stan": "22443",
"time": "122249",
"transactionIdentifier": "014VPH"
},
"customer": {
"firstName": "XXXX"
},
"device": {
},
"gatewayEntryPoint": "CHECKOUT",
"merchant": "XXXX",
"order": {
"amount": 33,
"chargeback": {
"amount": 0,
"currency": "USD"
},
"creationTime": "2021-11-06T12:22:49.602Z",
"currency": "USD",
"description": "243",
"id": "xxxxx",
"lastUpdatedTime": "2021-11-06T12:22:51.689Z",
"merchantAmount": 33,
"merchantCategoryCode": "xxx",
"merchantCurrency": "IQD",
"reference": "243",
"status": "CAPTURED",
"totalAuthorizedAmount": 33,
"totalCapturedAmount": 33,
"totalRefundedAmount": 0
},
"response": {
"acquirerCode": "00",
"acquirerMessage": "Approved",
"cardSecurityCode": {
"acquirerCode": "M",
"gatewayCode": "MATCH"
},
"gatewayCode": "APPROVED"
},
"result": "SUCCESS",
"sourceOfFunds": {
"provided": {
"card": {
"brand": "MASTERCARD",
"expiry": {
"month": "x",
"year": "xx"
},
"fundingMethod": "DEBIT",
"nameOnCard": "xxxxx",
"number": "xxxxxx",
"scheme": "MASTERCARD",
"storedOnFile": "NOT_STORED"
}
},
"type": "CARD"
},
"timeOfLastUpdate": "2021-11-06T12:22:51.689Z",
"timeOfRecord": "2021-11-06T12:22:49.617Z",
}
]
}
I'd like to extract "status": "CAPTURED" and "acquirerCode": "00" . here is what I tried
var client = new HttpClient();
string _ContentType = "application/json";
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_ContentType));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64EncodedAuthenticationString);
var _UserAgent = "d-fens HttpClient";
client.DefaultRequestHeaders.Add("User-Agent", _UserAgent);
HttpResponseMessage response;
response = await client.GetAsync(api_URL);
var resContent = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
var content = response.Content.ReadAsStringAsync().Result;
return Ok(resContent);
Extracting these values would solve the issue I'm facing. Thanks in advance
if you need just this 2 values the easiest way is
var json = response.Content.ReadAsStringAsync().Result;
var result = JObject.Parse(json);
var status= result["status"];
var acquirerCode= result["transaction"][0]["response"]["acquirerCode"];
output
CAPTURED
00
And there is a hard way
var json = response.Content.ReadAsStringAsync().Result;
var jsonDeserialized=JsonConvert.DeserializeObject<Data>(json);
var status= jsonDeserialized.Status;
var acquirerCode=jsonDeserialized.Transaction.Select(t => t.Response.AcquirerCode).FirstOrDefault();
classes
public partial class Data
{
[JsonProperty("creationTime")]
public DateTimeOffset CreationTime { get; set; }
[JsonProperty("currency")]
public string Currency { get; set; }
[JsonProperty("customer")]
public Customer Customer { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("lastUpdatedTime")]
public DateTimeOffset LastUpdatedTime { get; set; }
[JsonProperty("merchant")]
public string Merchant { get; set; }
[JsonProperty("merchantAmount")]
public long MerchantAmount { get; set; }
[JsonProperty("merchantCategoryCode")]
public long MerchantCategoryCode { get; set; }
[JsonProperty("merchantCurrency")]
public string MerchantCurrency { get; set; }
[JsonProperty("reference")]
public string Reference { get; set; }
[JsonProperty("result")]
public string Result { get; set; }
[JsonProperty("sourceOfFunds")]
public SourceOfFunds SourceOfFunds { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("totalAuthorizedAmount")]
public long TotalAuthorizedAmount { get; set; }
[JsonProperty("totalCapturedAmount")]
public long TotalCapturedAmount { get; set; }
[JsonProperty("totalRefundedAmount")]
public long TotalRefundedAmount { get; set; }
[JsonProperty("transaction")]
public Transaction[] Transaction { get; set; }
}
public partial class Customer
{
[JsonProperty("firstName")]
public string FirstName { get; set; }
}
public partial class SourceOfFunds
{
[JsonProperty("provided")]
public Provided Provided { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
}
public partial class Provided
{
[JsonProperty("card")]
public Card Card { get; set; }
}
public partial class Card
{
[JsonProperty("brand")]
public string Brand { get; set; }
[JsonProperty("expiry")]
public Expiry Expiry { get; set; }
[JsonProperty("fundingMethod")]
public string FundingMethod { get; set; }
[JsonProperty("nameOnCard")]
public string NameOnCard { get; set; }
[JsonProperty("number")]
public string Number { get; set; }
[JsonProperty("scheme")]
public string Scheme { get; set; }
[JsonProperty("storedOnFile")]
public string StoredOnFile { get; set; }
}
public partial class Expiry
{
[JsonProperty("month")]
public string Month { get; set; }
[JsonProperty("year")]
public string Year { get; set; }
}
public partial class Transaction
{
[JsonProperty("3DSecure")]
public The3DSecure The3DSecure { get; set; }
[JsonProperty("3DSecureId")]
public string The3DSecureId { get; set; }
[JsonProperty("authorizationResponse")]
public AuthorizationResponse AuthorizationResponse { get; set; }
[JsonProperty("customer")]
public Customer Customer { get; set; }
[JsonProperty("device")]
public Device Device { get; set; }
[JsonProperty("gatewayEntryPoint")]
public string GatewayEntryPoint { get; set; }
[JsonProperty("merchant")]
public string Merchant { get; set; }
[JsonProperty("order")]
public Order Order { get; set; }
[JsonProperty("response")]
public Response Response { get; set; }
[JsonProperty("result")]
public string Result { get; set; }
[JsonProperty("sourceOfFunds")]
public SourceOfFunds SourceOfFunds { get; set; }
[JsonProperty("timeOfLastUpdate")]
public DateTimeOffset TimeOfLastUpdate { get; set; }
[JsonProperty("timeOfRecord")]
public DateTimeOffset TimeOfRecord { get; set; }
}
public partial class AuthorizationResponse
{
[JsonProperty("cardSecurityCodeError")]
public string CardSecurityCodeError { get; set; }
[JsonProperty("commercialCardIndicator")]
public long CommercialCardIndicator { get; set; }
[JsonProperty("date")]
public long Date { get; set; }
[JsonProperty("financialNetworkCode")]
public string FinancialNetworkCode { get; set; }
[JsonProperty("financialNetworkDate")]
public DateTimeOffset FinancialNetworkDate { get; set; }
[JsonProperty("posData")]
public string PosData { get; set; }
[JsonProperty("posEntryMode")]
public string PosEntryMode { get; set; }
[JsonProperty("processingCode")]
public string ProcessingCode { get; set; }
[JsonProperty("responseCode")]
public string ResponseCode { get; set; }
[JsonProperty("stan")]
public long Stan { get; set; }
[JsonProperty("time")]
public long Time { get; set; }
[JsonProperty("transactionIdentifier")]
public string TransactionIdentifier { get; set; }
}
public partial class Device
{
}
public partial class Order
{
[JsonProperty("amount")]
public long Amount { get; set; }
[JsonProperty("chargeback")]
public Chargeback Chargeback { get; set; }
[JsonProperty("creationTime")]
public DateTimeOffset CreationTime { get; set; }
[JsonProperty("currency")]
public string Currency { get; set; }
[JsonProperty("description")]
public long Description { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("lastUpdatedTime")]
public DateTimeOffset LastUpdatedTime { get; set; }
[JsonProperty("merchantAmount")]
public long MerchantAmount { get; set; }
[JsonProperty("merchantCategoryCode")]
public string MerchantCategoryCode { get; set; }
[JsonProperty("merchantCurrency")]
public string MerchantCurrency { get; set; }
[JsonProperty("reference")]
public long Reference { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("totalAuthorizedAmount")]
public long TotalAuthorizedAmount { get; set; }
[JsonProperty("totalCapturedAmount")]
public long TotalCapturedAmount { get; set; }
[JsonProperty("totalRefundedAmount")]
public long TotalRefundedAmount { get; set; }
}
public partial class Chargeback
{
[JsonProperty("amount")]
public long Amount { get; set; }
[JsonProperty("currency")]
public string Currency { get; set; }
}
public partial class Response
{
[JsonProperty("acquirerCode")]
public string AcquirerCode { get; set; }
[JsonProperty("acquirerMessage")]
public string AcquirerMessage { get; set; }
[JsonProperty("cardSecurityCode")]
public CardSecurityCode CardSecurityCode { get; set; }
[JsonProperty("gatewayCode")]
public string GatewayCode { get; set; }
}
public partial class CardSecurityCode
{
[JsonProperty("acquirerCode")]
public string AcquirerCode { get; set; }
[JsonProperty("gatewayCode")]
public string GatewayCode { get; set; }
}
public partial class The3DSecure
{
[JsonProperty("acsEci")]
public string AcsEci { get; set; }
[JsonProperty("authenticationToken")]
public string AuthenticationToken { get; set; }
[JsonProperty("paResStatus")]
public string PaResStatus { get; set; }
[JsonProperty("veResEnrolled")]
public string VeResEnrolled { get; set; }
[JsonProperty("xid")]
public string Xid { get; set; }
}

How to deserialize JSON data from Jira?

In Visual Studio I am able to make a connection to Jira witch returns the string (shortened to one instance for the example)
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "15237",
"self": "https://companyName.atlassian.net/rest/agile/1.0/issue/15237",
"key": "THU-219",
"fields": {
"customfield_10110": null,
"fixVersions": [],
"customfield_10111": null,
"customfield_10112": null,
"resolution": null,
"customfield_10113": [
"com.atlassian.greenhopper.service.sprint.Sprint#a34aea2[id=53,rapidViewId=9,state=CLOSED,name=THU Sprint 7,goal=Survive!,startDate=2018-03-07T22:33:01.297Z,endDate=2018-03-21T22:33:00.000Z,completeDate=2018-03-20T19:16:10.159Z,sequence=53]",
"com.atlassian.greenhopper.service.sprint.Sprint#28b8057[id=58,rapidViewId=9,state=ACTIVE,name=THU Sprint 8,goal=make sure fixes fix ticket,startDate=2018-03-20T19:16:10.291Z,endDate=2018-04-03T19:16:00.000Z,completeDate=<null>,sequence=58]",
"com.atlassian.greenhopper.service.sprint.Sprint#3e1efb35[id=43,rapidViewId=9,state=CLOSED,name=THU Sprint 5,goal=,startDate=2018-02-06T20:44:37.751Z,endDate=2018-02-20T20:44:00.000Z,completeDate=2018-02-20T20:15:10.688Z,sequence=43]",
"com.atlassian.greenhopper.service.sprint.Sprint#2ce8e5a0[id=48,rapidViewId=9,state=CLOSED,name=THU Sprint 6,goal=,startDate=2018-02-20T20:15:01.461Z,endDate=2018-03-06T20:15:00.000Z,completeDate=2018-03-07T22:32:22.792Z,sequence=48]"
],
"customfield_10114": "1|hzz39z:",
"customfield_10500": null,
"customfield_10104": null,
"customfield_10105": null,
"customfield_10501": null,
"customfield_10106": null,
"customfield_10502": null,
"customfield_10503": null,
"customfield_10107": null,
"customfield_10108": null,
"customfield_10109": null,
"lastViewed": null,
"epic": {
"id": 15229,
"key": "THU-211",
"self": "https://companyName.atlassian.net/rest/agile/1.0/epic/15229",
"name": "project Name",
"summary": "Epic encompassing all TBD-related issues",
"color": {
"key": "color_2"
},
"done": false
},
"priority": {
"self": "https://nebook.atlassian.net/rest/api/2/priority/1",
"iconUrl": "https://companyName.atlassian.net/images/icons/priorities/highest.svg",
"name": "Highest",
"id": "1"
},
"customfield_10100": "2018-01-23T17:12:27.999-0600",
"customfield_10101": null,
"customfield_10102": null,
"labels": [
"user's first name"
],
"customfield_10103": null,
"customfield_10731": null,
"customfield_10610": null,
"customfield_10611": null,
"customfield_10733": null,
"customfield_10612": null,
"customfield_10613": null,
"timeestimate": null,
"customfield_10614": null,
"aggregatetimeoriginalestimate": null,
"customfield_10735": null,
"customfield_10615": null,
"versions": [],
"customfield_10616": null,
"customfield_10617": null,
"issuelinks": [
{
"id": "14337",
"self": "https://companyName.atlassian.net/rest/api/2/issueLink/14337",
"type": {
"id": "10000",
"name": "Blocks",
"inward": "is blocked by",
"outward": "blocks",
"self": "https://companyName.atlassian.net/rest/api/2/issueLinkType/10000"
},
"inwardIssue": {
"id": "18233",
"key": "THU-289",
"self": "https://companyName.atlassian.net/rest/api/2/issue/18233",
"fields": {
"summary": "summary",
"status": {
"self": "https://companyName.atlassian.net/rest/api/2/status/10804",
"description": "",
"iconUrl": "https://companyName.atlassian.net/images/icons/statuses/generic.png",
"name": "Code Review",
"id": "10804",
"statusCategory": {
"self": "https://companyName.atlassian.net/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
"priority": {
"self": "https://companyName.atlassian.net/rest/api/2/priority/1",
"iconUrl": "https://companyName.atlassian.net/images/icons/priorities/highest.svg",
"name": "Highest",
"id": "1"
},
"issuetype": {
"self": "https://companyName.atlassian.net/rest/api/2/issuetype/10300",
"id": "10300",
"description": "Created by Jira Agile - do not edit or delete. Issue type for a user story.",
"iconUrl": "https://companyName.atlassian.net/images/icons/issuetypes/story.svg",
"name": "Story",
"subtask": false
}
}
}
},
{
"id": "14336",
"self": "https://companyName.atlassian.net/rest/api/2/issueLink/14336",
"type": {
"id": "10001",
"name": "Cloners",
"inward": "is cloned by",
"outward": "clones",
"self": "https://companyName.atlassian.net/rest/api/2/issueLinkType/10001"
},
"inwardIssue": {
"id": "18233",
"key": "THU-289",
"self": "https://companyName.atlassian.net/rest/api/2/issue/18233",
"fields": {
"summary": "summary",
"status": {
"self": "https://companyName.atlassian.net/rest/api/2/status/10804",
"description": "",
"iconUrl": "https://companyName.atlassian.net/images/icons/statuses/generic.png",
"name": "Code Review",
"id": "10804",
"statusCategory": {
"self": "https://companyName.atlassian.net/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
"priority": {
"self": "https://companyName.atlassian.net/rest/api/2/priority/1",
"iconUrl": "https://companyName.atlassian.net/images/icons/priorities/highest.svg",
"name": "Highest",
"id": "1"
},
"issuetype": {
"self": "https://companyName.atlassian.net/rest/api/2/issuetype/10300",
"id": "10300",
"description": "Created by Jira Agile - do not edit or delete. Issue type for a user story.",
"iconUrl": "https://companyName.atlassian.net/images/icons/issuetypes/story.svg",
"name": "Story",
"subtask": false
}
}
}
}
],
"assignee": null,
"status": {
"self": "https://companyName.atlassian.net/rest/api/2/status/10804",
"description": "",
"iconUrl": "https://companyName.atlassian.net/images/icons/statuses/generic.png",
"name": "Code Review",
"id": "10804",
"statusCategory": {
"self": "https://companyName.atlassian.net/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
"components": [],
"customfield_10730": null,
"customfield_10600": null,
"customfield_10601": null,
"customfield_10602": null,
"aggregatetimeestimate": null,
"customfield_10603": null,
"customfield_10604": null,
"customfield_10605": null,
"customfield_10727": null,
"customfield_10606": null,
"customfield_10728": null,
"customfield_10607": null,
"customfield_10608": null,
"customfield_10729": null,
"customfield_10609": null,
"creator": {
"self": "https://companyName.atlassian.net/rest/api/2/user?username=name",
"name": "name",
"key": "key",
"accountId": "accountId",
"emailAddress": "email",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/40f53dffbd45ed6f545a40ec91d4843f?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F40f53dffbd45ed6f545a40ec91d4843f%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/40f53dffbd45ed6f545a40ec91d4843f?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F40f53dffbd45ed6f545a40ec91d4843f%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/40f53dffbd45ed6f545a40ec91d4843f?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F40f53dffbd45ed6f545a40ec91d4843f%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/40f53dffbd45ed6f545a40ec91d4843f?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F40f53dffbd45ed6f545a40ec91d4843f%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "name",
"active": true,
"timeZone": "America/Chicago"
},
"subtasks": [],
"reporter": {
"self": "https://companyName.atlassian.net/rest/api/2/user?username=name",
"name": "name",
"key": "key",
"accountId": "557058:ecce9327-53cc-4787-bcd5-ecf16309600b",
"emailAddress": "email",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/40f53dffbd45ed6f545a40ec91d4843f?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F40f53dffbd45ed6f545a40ec91d4843f%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/40f53dffbd45ed6f545a40ec91d4843f?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F40f53dffbd45ed6f545a40ec91d4843f%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/40f53dffbd45ed6f545a40ec91d4843f?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F40f53dffbd45ed6f545a40ec91d4843f%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/40f53dffbd45ed6f545a40ec91d4843f?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F40f53dffbd45ed6f545a40ec91d4843f%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "name",
"active": true,
"timeZone": "America/Chicago"
},
"aggregateprogress": {
"progress": 0,
"total": 0
},
"customfield_10711": null,
"customfield_10712": null,
"closedSprints": [
{
"id": 53,
"self": "https://companyName.atlassian.net/rest/agile/1.0/sprint/53",
"state": "closed",
"name": "THU Sprint 7",
"startDate": "2018-03-07T22:33:01.297Z",
"endDate": "2018-03-21T22:33:00.000Z",
"completeDate": "2018-03-20T19:16:10.159Z",
"originBoardId": 9,
"goal": "Survive!"
},
{
"id": 43,
"self": "https://companyName.atlassian.net/rest/agile/1.0/sprint/43",
"state": "closed",
"name": "THU Sprint 5",
"startDate": "2018-02-06T20:44:37.751Z",
"endDate": "2018-02-20T20:44:00.000Z",
"completeDate": "2018-02-20T20:15:10.688Z",
"originBoardId": 9,
"goal": ""
},
{
"id": 48,
"self": "https://companyName.atlassian.net/rest/agile/1.0/sprint/48",
"state": "closed",
"name": "THU Sprint 6",
"startDate": "2018-02-20T20:15:01.461Z",
"endDate": "2018-03-06T20:15:00.000Z",
"completeDate": "2018-03-07T22:32:22.792Z",
"originBoardId": 9,
"goal": ""
}
],
"progress": {
"progress": 0,
"total": 0
},
"votes": {
"self": "https://companyName.atlassian.net/rest/api/2/issue/THU-219/votes",
"votes": 0,
"hasVoted": false
},
"worklog": {
"startAt": 0,
"maxResults": 20,
"total": 0,
"worklogs": []
},
"issuetype": {
"self": "https://companyName.atlassian.net/rest/api/2/issuetype/10300",
"id": "10300",
"description": "Created by Jira Agile - do not edit or delete. Issue type for a user story.",
"iconUrl": "https://companyName.atlassian.net/images/icons/issuetypes/story.svg",
"name": "Story",
"subtask": false
},
"timespent": null,
"sprint": {
"id": 58,
"self": "https://companyName.atlassian.net/rest/agile/1.0/sprint/58",
"state": "active",
"name": "THU Sprint 8",
"startDate": "2018-03-20T19:16:10.291Z",
"endDate": "2018-04-03T19:16:00.000Z",
"originBoardId": 9,
"goal": "make sure fixes fix ticket"
},
"project": {
"self": "https://nebook.atlassian.net/rest/api/2/project/11510",
"id": "11510",
"key": "THU",
"name": "name",
"projectTypeKey": "software",
"avatarUrls": {
"48x48": "https://nebook.atlassian.net/secure/projectavatar?avatarId=10324",
"24x24": "https://nebook.atlassian.net/secure/projectavatar?size=small&avatarId=10324",
"16x16": "https://nebook.atlassian.net/secure/projectavatar?size=xsmall&avatarId=10324",
"32x32": "https://nebook.atlassian.net/secure/projectavatar?size=medium&avatarId=10324"
}
},
"aggregatetimespent": null,
"resolutiondate": null,
"workratio": -1,
"watches": {
"self": "https://companyName.atlassian.net/rest/api/2/issue/THU-219/watchers",
"watchCount": 2,
"isWatching": false
},
"created": "2017-12-14T18:01:28.505-0600",
"customfield_10300": null,
"customfield_10301": null,
"updated": "2018-03-20T14:16:13.195-0500",
"timeoriginalestimate": null,
"description": "description",
"timetracking": {},
"customfield_10401": [],
"customfield_10402": null,
"customfield_10006": "THU-211",
"customfield_10403": null,
"security": null,
"customfield_10007": null,
"attachment": [],
"flagged": false,
"summary": "summary",
"customfield_10000": "{}",
"customfield_10001": null,
"customfield_10002": null,
"customfield_10400": null,
"environment": null,
"duedate": null,
"comment": {
"comments": [
{
"self": "https://companyName.atlassian.net/rest/api/2/issue/15237/comment/23890",
"id": "23890",
"author": {
"self": "https://companyName.atlassian.net/rest/api/2/user?username=name",
"name": "name",
"key": "key",
"accountId": "accountId",
"emailAddress": "email",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/b232453b514d10d65f986fe7f2df592c?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fb232453b514d10d65f986fe7f2df592c%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/b232453b514d10d65f986fe7f2df592c?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fb232453b514d10d65f986fe7f2df592c%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/b232453b514d10d65f986fe7f2df592c?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fb232453b514d10d65f986fe7f2df592c%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/b232453b514d10d65f986fe7f2df592c?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fb232453b514d10d65f986fe7f2df592c%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "name",
"active": true,
"timeZone": "America/Chicago"
},
"body": "text describing the issue",
"updateAuthor": {
"self": "https://companyName.atlassian.net/rest/api/2/user?username=name",
"name": "name",
"key": "key",
"accountId": "557058:d4a31d0e-7944-488b-9f89-fcfec87b95ac",
"emailAddress": "email",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/b232453b514d10d65f986fe7f2df592c?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fb232453b514d10d65f986fe7f2df592c%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/b232453b514d10d65f986fe7f2df592c?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fb232453b514d10d65f986fe7f2df592c%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/b232453b514d10d65f986fe7f2df592c?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fb232453b514d10d65f986fe7f2df592c%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/b232453b514d10d65f986fe7f2df592c?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fb232453b514d10d65f986fe7f2df592c%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "name",
"active": true,
"timeZone": "America/Chicago"
},
"created": "2018-01-23T17:12:27.999-0600",
"updated": "2018-01-23T17:12:27.999-0600"
}
],
"maxResults": 1,
"total": 1,
"startAt": 0
}
}
},
I have been able to find some examples on here that deal with this issue however I have not been able to find anything that deals with repeated key words like my JSON data has.
The only real information I care about is the initial "Key" value (In this example "THU-219") and the status "name" field which is under "fields" -> "issuelinks" -> "inwardIssue" -> "fields" -> "status" -> "name"
I would like to be able to print out in the form of
Key: THU-219 \n
Status: "Code Review"
To achieve this I have attempted this code (after I have made a secure connection)Where respStr is the entire string which contains the snippet above in the same format for each issue. Am I creating my classes wrong? Because I am unable to get the expected data. I am aware that there is an option in Visual studio to "paste as JSON classes" but I getting an error that won't allow me to utilize this feature so I need a way to accomplish this without relying on that paste special feature.
String respStr = response.Content;
JiraObject jira = JsonConvert.DeserializeObject<JiraObject>(respStr);
foreach (KeyValuePair<string, Key>kvp in jira.Issues)
{
Console.WriteLine("Key:" + kvp.Value.Keys);
Console.WriteLine("Status:" + kvp.Value.Status)
Console.WriteLine();
}
Console.ReadKey();
}
}
class JiraObject
{
[JsonProperty("issues")]
public Dictionary<string, issues> Issues { get; set; }
}
class issues
{
[JsonProperty("key")]
public Dictionary<string, Key> Keys { get; set; }
[JsonProperty("fields")]
public Dictionary<string, Fields> fields { get; set; }
}
class Key
{
public Key Keys { get; set; }
}
class Fields
{
[JsonProperty("issuelinks")]
public Dictionary<string, issuelinks> issueLinks { get; set; }
}
class issuelinks
{
[JsonProperty("inwardIssue")]
public Dictionary<string,inwardIssue> inwardIssues { get; set; }
}
class inwardIssue
{
[JsonProperty("fields")]
public Dictionary<string, inwardFields> inwardFields { get; set; }
}
class inwardFields
{
[JsonProperty("status")]
public Dictionary<string, status> status { get; set; }
}
class status
{
[JsonProperty("name")]
public Dictionary<string,name> name { get; set; }
}
class name
{
public name names { get; set; }
}
As pointed out by Kevin Avignon your JSON is not valid. It's missing a "{" at the beginning and you need to remove the "," at the end so that we can use it (but this were just a minor problem).
In order to get the classes you need you can just dump your JSON into json2csharp.com. In your case i got the following:
public class Color
{
public string key { get; set; }
}
public class Epic
{
public int id { get; set; }
public string key { get; set; }
public string self { get; set; }
public string name { get; set; }
public string summary { get; set; }
public Color color { get; set; }
public bool done { get; set; }
}
public class Priority
{
public string self { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
}
public class Type
{
public string id { get; set; }
public string name { get; set; }
public string inward { get; set; }
public string outward { get; set; }
public string self { get; set; }
}
public class StatusCategory
{
public string self { get; set; }
public int id { get; set; }
public string key { get; set; }
public string colorName { get; set; }
public string name { get; set; }
}
public class Status
{
public string self { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
public StatusCategory statusCategory { get; set; }
}
public class Priority2
{
public string self { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
}
public class Issuetype
{
public string self { get; set; }
public string id { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public bool subtask { get; set; }
}
public class Fields2
{
public string summary { get; set; }
public Status status { get; set; }
public Priority2 priority { get; set; }
public Issuetype issuetype { get; set; }
}
public class InwardIssue
{
public string id { get; set; }
public string key { get; set; }
public string self { get; set; }
public Fields2 fields { get; set; }
}
public class Issuelink
{
public string id { get; set; }
public string self { get; set; }
public Type type { get; set; }
public InwardIssue inwardIssue { get; set; }
}
public class StatusCategory2
{
public string self { get; set; }
public int id { get; set; }
public string key { get; set; }
public string colorName { get; set; }
public string name { get; set; }
}
public class Status2
{
public string self { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
public StatusCategory2 statusCategory { get; set; }
}
public class AvatarUrls
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Creator
{
public string self { get; set; }
public string name { get; set; }
public string key { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
}
public class AvatarUrls2
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Reporter
{
public string self { get; set; }
public string name { get; set; }
public string key { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls2 avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
}
public class Aggregateprogress
{
public int progress { get; set; }
public int total { get; set; }
}
public class ClosedSprint
{
public int id { get; set; }
public string self { get; set; }
public string state { get; set; }
public string name { get; set; }
public DateTime startDate { get; set; }
public DateTime endDate { get; set; }
public DateTime completeDate { get; set; }
public int originBoardId { get; set; }
public string goal { get; set; }
}
public class Progress
{
public int progress { get; set; }
public int total { get; set; }
}
public class Votes
{
public string self { get; set; }
public int votes { get; set; }
public bool hasVoted { get; set; }
}
public class Worklog
{
public int startAt { get; set; }
public int maxResults { get; set; }
public int total { get; set; }
public List<object> worklogs { get; set; }
}
public class Issuetype2
{
public string self { get; set; }
public string id { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public bool subtask { get; set; }
}
public class Sprint
{
public int id { get; set; }
public string self { get; set; }
public string state { get; set; }
public string name { get; set; }
public DateTime startDate { get; set; }
public DateTime endDate { get; set; }
public int originBoardId { get; set; }
public string goal { get; set; }
}
public class AvatarUrls3
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Project
{
public string self { get; set; }
public string id { get; set; }
public string key { get; set; }
public string name { get; set; }
public string projectTypeKey { get; set; }
public AvatarUrls3 avatarUrls { get; set; }
}
public class Watches
{
public string self { get; set; }
public int watchCount { get; set; }
public bool isWatching { get; set; }
}
public class Timetracking
{
}
public class AvatarUrls4
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Author
{
public string self { get; set; }
public string name { get; set; }
public string key { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls4 avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
}
public class AvatarUrls5
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class UpdateAuthor
{
public string self { get; set; }
public string name { get; set; }
public string key { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls5 avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
}
public class Comment2
{
public string self { get; set; }
public string id { get; set; }
public Author author { get; set; }
public string body { get; set; }
public UpdateAuthor updateAuthor { get; set; }
public DateTime created { get; set; }
public DateTime updated { get; set; }
}
public class Comment
{
public List<Comment2> comments { get; set; }
public int maxResults { get; set; }
public int total { get; set; }
public int startAt { get; set; }
}
public class Fields
{
public object customfield_10110 { get; set; }
public List<object> fixVersions { get; set; }
public object customfield_10111 { get; set; }
public object customfield_10112 { get; set; }
public object resolution { get; set; }
public List<string> customfield_10113 { get; set; }
public string customfield_10114 { get; set; }
public object customfield_10500 { get; set; }
public object customfield_10104 { get; set; }
public object customfield_10105 { get; set; }
public object customfield_10501 { get; set; }
public object customfield_10106 { get; set; }
public object customfield_10502 { get; set; }
public object customfield_10503 { get; set; }
public object customfield_10107 { get; set; }
public object customfield_10108 { get; set; }
public object customfield_10109 { get; set; }
public object lastViewed { get; set; }
public Epic epic { get; set; }
public Priority priority { get; set; }
public DateTime customfield_10100 { get; set; }
public object customfield_10101 { get; set; }
public object customfield_10102 { get; set; }
public List<string> labels { get; set; }
public object customfield_10103 { get; set; }
public object customfield_10731 { get; set; }
public object customfield_10610 { get; set; }
public object customfield_10611 { get; set; }
public object customfield_10733 { get; set; }
public object customfield_10612 { get; set; }
public object customfield_10613 { get; set; }
public object timeestimate { get; set; }
public object customfield_10614 { get; set; }
public object aggregatetimeoriginalestimate { get; set; }
public object customfield_10735 { get; set; }
public object customfield_10615 { get; set; }
public List<object> versions { get; set; }
public object customfield_10616 { get; set; }
public object customfield_10617 { get; set; }
public List<Issuelink> issuelinks { get; set; }
public object assignee { get; set; }
public Status2 status { get; set; }
public List<object> components { get; set; }
public object customfield_10730 { get; set; }
public object customfield_10600 { get; set; }
public object customfield_10601 { get; set; }
public object customfield_10602 { get; set; }
public object aggregatetimeestimate { get; set; }
public object customfield_10603 { get; set; }
public object customfield_10604 { get; set; }
public object customfield_10605 { get; set; }
public object customfield_10727 { get; set; }
public object customfield_10606 { get; set; }
public object customfield_10728 { get; set; }
public object customfield_10607 { get; set; }
public object customfield_10608 { get; set; }
public object customfield_10729 { get; set; }
public object customfield_10609 { get; set; }
public Creator creator { get; set; }
public List<object> subtasks { get; set; }
public Reporter reporter { get; set; }
public Aggregateprogress aggregateprogress { get; set; }
public object customfield_10711 { get; set; }
public object customfield_10712 { get; set; }
public List<ClosedSprint> closedSprints { get; set; }
public Progress progress { get; set; }
public Votes votes { get; set; }
public Worklog worklog { get; set; }
public Issuetype2 issuetype { get; set; }
public object timespent { get; set; }
public Sprint sprint { get; set; }
public Project project { get; set; }
public object aggregatetimespent { get; set; }
public object resolutiondate { get; set; }
public int workratio { get; set; }
public Watches watches { get; set; }
public DateTime created { get; set; }
public object customfield_10300 { get; set; }
public object customfield_10301 { get; set; }
public DateTime updated { get; set; }
public object timeoriginalestimate { get; set; }
public string description { get; set; }
public Timetracking timetracking { get; set; }
public List<object> customfield_10401 { get; set; }
public object customfield_10402 { get; set; }
public string customfield_10006 { get; set; }
public object customfield_10403 { get; set; }
public object security { get; set; }
public object customfield_10007 { get; set; }
public List<object> attachment { get; set; }
public bool flagged { get; set; }
public string summary { get; set; }
public string customfield_10000 { get; set; }
public object customfield_10001 { get; set; }
public object customfield_10002 { get; set; }
public object customfield_10400 { get; set; }
public object environment { get; set; }
public object duedate { get; set; }
public Comment comment { get; set; }
}
public class RootObject
{
public string expand { get; set; }
public string id { get; set; }
public string self { get; set; }
public string key { get; set; }
public Fields fields { get; set; }
}
Now you only need to remove everything that you don't need (and maybe rename class names if you want). After doing so you will have your classes that you can work with.
The following classes will just store the initial "key" value and the "name" of the status as you asked for in your post.
public class Status
{
public string Name { get; set; }
}
public class Fields2
{
public Status Status { get; set; }
}
public class InwardIssue
{
public Fields2 Fields { get; set; }
}
public class Issuelink
{
public InwardIssue InwardIssue { get; set; }
}
public class Fields
{
public List<Issuelink> Issuelinks { get; set; }
}
public class RootObject
{
public string Key { get; set; }
public Fields Fields { get; set; }
}
To deserialize your json you can now use the following code:
string content = //your json
RootObject ro = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(content);
If something is still wrong then pls write so and i will try to figure something out.
Fabian,
Below are the generated classes from the website you provided after I put my entire JSON string into the website.
public class I18nErrorMessage
{
public string i18nKey { get; set; }
public List<object> parameters { get; set; }
}
public class Customfield10502
{
public string errorMessage { get; set; }
public I18nErrorMessage i18nErrorMessage { get; set; }
}
public class I18nErrorMessage2
{
public string i18nKey { get; set; }
public List<object> parameters { get; set; }
}
public class Customfield10503
{
public string errorMessage { get; set; }
public I18nErrorMessage2 i18nErrorMessage { get; set; }
}
public class Color
{
public string key { get; set; }
}
public class Epic
{
public int id { get; set; }
public string key { get; set; }
public string self { get; set; }
public string name { get; set; }
public string summary { get; set; }
public Color color { get; set; }
public bool done { get; set; }
}
public class Priority
{
public string self { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
}
public class I18nErrorMessage3
{
public string i18nKey { get; set; }
public List<object> parameters { get; set; }
}
public class Customfield10616
{
public string errorMessage { get; set; }
public I18nErrorMessage3 i18nErrorMessage { get; set; }
}
public class AvatarUrls
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Assignee
{
public string self { get; set; }
public string name { get; set; }
public string key { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
}
public class StatusCategory
{
public string self { get; set; }
public int id { get; set; }
public string key { get; set; }
public string colorName { get; set; }
public string name { get; set; }
}
public class Status
{
public string self { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
public StatusCategory statusCategory { get; set; }
}
public class AvatarUrls2
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Creator
{
public string self { get; set; }
public string name { get; set; }
public string key { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls2 avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
}
public class AvatarUrls3
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Reporter
{
public string self { get; set; }
public string name { get; set; }
public string key { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls3 avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
}
public class Aggregateprogress
{
public int progress { get; set; }
public int total { get; set; }
}
public class Customfield10711
{
public string self { get; set; }
public string value { get; set; }
public string id { get; set; }
}
public class AvatarUrls4
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Customfield10712
{
public string self { get; set; }
public string name { get; set; }
public string key { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls4 avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
}
public class ClosedSprint
{
public int id { get; set; }
public string self { get; set; }
public string state { get; set; }
public string name { get; set; }
public DateTime startDate { get; set; }
public DateTime endDate { get; set; }
public DateTime completeDate { get; set; }
public int originBoardId { get; set; }
public string goal { get; set; }
}
public class Progress
{
public int progress { get; set; }
public int total { get; set; }
}
public class Votes
{
public string self { get; set; }
public int votes { get; set; }
public bool hasVoted { get; set; }
}
public class Worklog
{
public int startAt { get; set; }
public int maxResults { get; set; }
public int total { get; set; }
public List<object> worklogs { get; set; }
}
public class Issuetype
{
public string self { get; set; }
public string id { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public bool subtask { get; set; }
public int avatarId { get; set; }
}
public class Sprint
{
public int id { get; set; }
public string self { get; set; }
public string state { get; set; }
public string name { get; set; }
public DateTime startDate { get; set; }
public DateTime endDate { get; set; }
public int originBoardId { get; set; }
public string goal { get; set; }
}
public class AvatarUrls5
{
public string __invalid_name__48x48 { get; set; }
public string __invalid_name__24x24 { get; set; }
public string __invalid_name__16x16 { get; set; }
public string __invalid_name__32x32 { get; set; }
}
public class Project
{
public string self { get; set; }
public string id { get; set; }
public string key { get; set; }
public string name { get; set; }
public string projectTypeKey { get; set; }
public AvatarUrls5 avatarUrls { get; set; }
}
public class Watches
{
public string self { get; set; }
public int watchCount { get; set; }
public bool isWatching { get; set; }
}
public class Timetracking
{
}
public class I18nErrorMessage4
{
public string i18nKey { get; set; }
public List<object> parameters { get; set; }
}
public class Customfield10400
{
public string errorMessage { get; set; }
public I18nErrorMessage4 i18nErrorMessage { get; set; }
}
public class Comment
{
public List<object> comments { get; set; }
public int maxResults { get; set; }
public int total { get; set; }
public int startAt { get; set; }
}
public class StatusCategory2
{
public string self { get; set; }
public int id { get; set; }
public string key { get; set; }
public string colorName { get; set; }
public string name { get; set; }
}
public class Status2
{
public string self { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
public StatusCategory2 statusCategory { get; set; }
}
public class Priority2
{
public string self { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
}
public class Issuetype2
{
public string self { get; set; }
public string id { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public bool subtask { get; set; }
public int avatarId { get; set; }
}
public class Fields2
{
public string summary { get; set; }
public Status2 status { get; set; }
public Priority2 priority { get; set; }
public Issuetype2 issuetype { get; set; }
}
public class Parent
{
public string id { get; set; }
public string key { get; set; }
public string self { get; set; }
public Fields2 fields { get; set; }
}
public class Fields
{
public List<object> fixVersions { get; set; }
public object customfield_10110 { get; set; }
public object customfield_10111 { get; set; }
public object resolution { get; set; }
public object customfield_10112 { get; set; }
public List<string> customfield_10113 { get; set; }
public string customfield_10114 { get; set; }
public object customfield_10104 { get; set; }
public object customfield_10500 { get; set; }
public object customfield_10501 { get; set; }
public object customfield_10105 { get; set; }
public object customfield_10106 { get; set; }
public Customfield10502 customfield_10502 { get; set; }
public Customfield10503 customfield_10503 { get; set; }
public object customfield_10107 { get; set; }
public object customfield_10108 { get; set; }
public object customfield_10109 { get; set; }
public object lastViewed { get; set; }
public Epic epic { get; set; }
public Priority priority { get; set; }
public DateTime? customfield_10100 { get; set; }
public object customfield_10101 { get; set; }
public object customfield_10102 { get; set; }
public List<object> labels { get; set; }
public object customfield_10103 { get; set; }
public object customfield_10731 { get; set; }
public object customfield_10610 { get; set; }
public object customfield_10611 { get; set; }
public object customfield_10612 { get; set; }
public string customfield_10733 { get; set; }
public object customfield_10613 { get; set; }
public object timeestimate { get; set; }
public object customfield_10614 { get; set; }
public object aggregatetimeoriginalestimate { get; set; }
public DateTime? customfield_10735 { get; set; }
public List<object> versions { get; set; }
public object customfield_10615 { get; set; }
public Customfield10616 customfield_10616 { get; set; }
public object customfield_10617 { get; set; }
public List<object> issuelinks { get; set; }
public Assignee assignee { get; set; }
public Status status { get; set; }
public List<object> components { get; set; }
public object customfield_10730 { get; set; }
public object customfield_10600 { get; set; }
public object customfield_10601 { get; set; }
public object customfield_10602 { get; set; }
public object customfield_10603 { get; set; }
public object aggregatetimeestimate { get; set; }
public object customfield_10604 { get; set; }
public object customfield_10605 { get; set; }
public object customfield_10606 { get; set; }
public object customfield_10727 { get; set; }
public object customfield_10728 { get; set; }
public object customfield_10607 { get; set; }
public object customfield_10608 { get; set; }
public object customfield_10729 { get; set; }
public object customfield_10609 { get; set; }
public Creator creator { get; set; }
public List<object> subtasks { get; set; }
public Reporter reporter { get; set; }
public Aggregateprogress aggregateprogress { get; set; }
public Customfield10711 customfield_10711 { get; set; }
public Customfield10712 customfield_10712 { get; set; }
public List<ClosedSprint> closedSprints { get; set; }
public Progress progress { get; set; }
public Votes votes { get; set; }
public Worklog worklog { get; set; }
public Issuetype issuetype { get; set; }
public object timespent { get; set; }
public Sprint sprint { get; set; }
public Project project { get; set; }
public object aggregatetimespent { get; set; }
public object resolutiondate { get; set; }
public int workratio { get; set; }
public Watches watches { get; set; }
public DateTime created { get; set; }
public object customfield_10300 { get; set; }
public object customfield_10301 { get; set; }
public DateTime updated { get; set; }
public object timeoriginalestimate { get; set; }
public string description { get; set; }
public Timetracking timetracking { get; set; }
public List<object> customfield_10401 { get; set; }
public object customfield_10402 { get; set; }
public string customfield_10006 { get; set; }
public object customfield_10403 { get; set; }
public object security { get; set; }
public object customfield_10007 { get; set; }
public List<object> attachment { get; set; }
public bool flagged { get; set; }
public string summary { get; set; }
public string customfield_10000 { get; set; }
public object customfield_10001 { get; set; }
public object customfield_10002 { get; set; }
public Customfield10400 customfield_10400 { get; set; }
public object environment { get; set; }
public object duedate { get; set; }
public Comment comment { get; set; }
public string customfield_10710 { get; set; }
public Parent parent { get; set; }
}
public class Issue
{
public string expand { get; set; }
public string id { get; set; }
public string self { get; set; }
public string key { get; set; }
public Fields fields { get; set; }
}
public class RootObject
{
public string expand { get; set; }
public int startAt { get; set; }
public int maxResults { get; set; }
public int total { get; set; }
public List<Issue> issues { get; set; }
}
}
I figured I would rather have too many classes and get it to work then I can just weed out what I don't need after (might consider using other properties to generate other graphs, etc). Below is my code that I am trying. I have tried a few other variations but I still get that same unexpected character encountered error.
String respStr = response.Content;
RootObject ro = JsonConvert.DeserializeObject<RootObject>(respStr);
Console.WriteLine(ro.issues[0].key[0]);

Need to grab a parent value in Linq

I'm using this code to pull a list of email addresses and search them for a specific address, if it's a duplicate then I need to pull the "id" (the value starts with "lead_") which is in the Datam class and/or Contacts
var emails = json
// Enumerate through all data
.Data
// Enumerate through all contacts of all data
.SelectMany(d => d.Contacts)
// Enumerate through all emails of all contacts
.SelectMany(c => c.Emails)
// Get email value
.Select(e => e.EmailValue)
So I have my list of emails, but how do I attach the ID's to them, I assume I need to create an anonymous type?
I've tried this but can't figure out how to go back to the root
JSON:
{
"data": [
{
"addresses": [],
"contacts": [
{
"created_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"date_created": "2017-12-03T05:42:30.737000+00:00",
"date_updated": "2017-12-03T05:45:32.227000+00:00",
"emails": [
{
"email": "testemail#testemail.com",
"type": "office"
}
],
"id": "cont_kH9tcx970T3ZTGKPPP2vh5u3Ha8P9Rjz6gGqflgzwvy",
"integration_links": [
{
"name": "LinkedIn Search",
"url": "https://www.linkedin.com/search/results/index/?keywords=Test%20Woodard"
}
],
"lead_id": "lead_12Rz7R2TrWmwUhCGVTRh8rt6A8hokaXgujSEPlfoWpD",
"name": "Test User",
"organization_id": "orga_iFnIMLDbvGevDrXMHYQSbYnLu1GjrdM2TEWWsCoraJH",
"phones": [
{
"phone": "+15558675309",
"phone_formatted": "+1 555-867-5309",
"type": "office"
}
],
"title": "",
"updated_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"urls": []
}
],
"created_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"created_by_name": "Test User",
"custom": {
"Date Created": "2017-12-03",
"Initial Service": "Men's Health",
"Lead Owner": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"Marketing Source": "Bing"
},
"custom.lcf_UfNWMxg2f7UU28rI9RAhTEAPWMyXU1UFZb5oNJEgR0K": "Bing",
"custom.lcf_dDtwGb41tpi8XkVMMgxdHxEJ92A7ujreRU1aPPZd95B": "Chiropractor",
"custom.lcf_fUNjcSq8bemwdQL0wogc3wgyxmz3ZD17fKdv8s4wkWV": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"custom.lcf_y37bo72LesrOBWuVPSoRfIazw5KflujnV81nGCfcjZ3": "2017-12-03",
"date_created": "2017-12-03T05:42:30.733000+00:00",
"date_updated": "2017-12-03T05:45:32.234000+00:00",
"description": "",
"display_name": "test",
"html_url": "https://app.close.io/lead/lead_12Rz7R2TrWmwUhCFVTRh8rt6A8hokaXgujSEPlfoWpG/",
"id": "lead_12Rz7R2TrWmwUhCFVTRh8rt6A8hokaXgujSEPlfoWpD",
"integration_links": [
{
"name": "Google Search",
"url": "http://google.com/search?q=test"
}
],
"name": "test",
"opportunities": [
{
"confidence": 50,
"contact_id": null,
"contact_name": null,
"created_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"created_by_name": "Test User",
"date_created": "2017-12-03T05:44:31.131000+00:00",
"date_lost": null,
"date_updated": "2017-12-03T05:44:31.131000+00:00",
"date_won": null,
"id": "oppo_xQ5S1dHMjDWoeUBAigtyiwuwFUkxtbxHURQX5UaL7fT",
"integration_links": [],
"lead_id": "lead_12Rz7R2TrWmwUhCFVTRh8rt6A8hokaXgujSEPlfoWpD",
"lead_name": "test",
"note": "New Lead",
"organization_id": "orga_iFnIMLDbvNevDrXMHYQSbYnLu1GjrdM2TEWWsCoraJH",
"status_id": "stat_SwQmzqoIqIt20j9YBDxIYem11GyZPGL30G7PdkWYdvG",
"status_label": "Chiropractor",
"status_type": "active",
"updated_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"updated_by_name": "Test User",
"user_id": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"user_name": "Test User",
"value": 140000,
"value_currency": "USD",
"value_formatted": "$1,400",
"value_period": "one_time"
}
],
"organization_id": "orga_iFnIMLDbvNevDrXMHYQSbYnLu1GjrdM2TEWWsCoraJH",
"status_id": "stat_auhCEJZNhaUnX9DHdrCaZ5r5mhpqxjfaE1hdwnPz6xx",
"status_label": "Potential",
"tasks": [],
"updated_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"updated_by_name": "Test User",
"url": null
}
],
"has_more": false,
"total_results": 1
}
public partial class Welcome
{
[JsonProperty("data")]
public Datum[] Data { get; set; }
[JsonProperty("has_more")]
public bool HasMore { get; set; }
[JsonProperty("total_results")]
public long TotalResults { get; set; }
}
public partial class Datum
{
[JsonProperty("addresses")]
public object[] Addresses { get; set; }
[JsonProperty("contacts")]
public Contact[] Contacts { get; set; }
[JsonProperty("created_by")]
public string CreatedBy { get; set; }
[JsonProperty("created_by_name")]
public string CreatedByName { get; set; }
[JsonProperty("custom")]
public Custom Custom { get; set; }
[JsonProperty("custom.lcf_dDtwGb41tpi8XkVMMgxdHxEJ92A7ujreRU1aPPZd95B")]
public string CustomInitialService { get; set; }
[JsonProperty("custom.lcf_fUNjcSq8bemwdQL0wogc3wgyxmz3ZD17fKdv8s4wkWV")]
public string CustomLeadOwner { get; set; }
[JsonProperty("custom.lcf_UfNWMxg2f7UU28rI9RAhTEAPWMyXU1UFZb5oNJEgR0K")]
public string CustomMarketingSource { get; set; }
[JsonProperty("custom.lcf_y37bo72LesrOBWuVPSoRfIazw5KflujnV81nGCfcjZ3")]
public string CustomDateCreated { get; set; }
[JsonProperty("custom.lcf_bzaGzJw0MsgtffSeHDQhYjfBmacMWxCiPM3DlqOlYZQ")]
public string CustomLocation { get; set; }
[JsonProperty("custom.lcf_1EE18uGReRLF6xqI45kWA3ijfSWJTe718FSgTiXdyEC")]
public string CustomStart { get; set; }
[JsonProperty("custom.lcf_E23dCjch37Zushwm1ZzPm3JXKXKJMZgYEYBjx5oabDF")]
public string CustomAppointment { get; set; }
[JsonProperty("date_created")]
public string DateCreated { get; set; }
[JsonProperty("date_updated")]
public string DateUpdated { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("display_name")]
public string DisplayName { get; set; }
[JsonProperty("html_url")]
public string HtmlUrl { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("integration_links")]
public IntegrationLink[] IntegrationLinks { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("opportunities")]
public Opportunity[] Opportunities { get; set; }
[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
[JsonProperty("status_id")]
public string StatusId { get; set; }
[JsonProperty("status_label")]
public string StatusLabel { get; set; }
[JsonProperty("tasks")]
public object[] Tasks { get; set; }
[JsonProperty("updated_by")]
public string UpdatedBy { get; set; }
[JsonProperty("updated_by_name")]
public string UpdatedByName { get; set; }
[JsonProperty("url")]
public object Url { get; set; }
}
public partial class Opportunity
{
[JsonProperty("confidence")]
public long Confidence { get; set; }
[JsonProperty("contact_id")]
public object ContactId { get; set; }
[JsonProperty("contact_name")]
public object ContactName { get; set; }
[JsonProperty("created_by")]
public string CreatedBy { get; set; }
[JsonProperty("created_by_name")]
public string CreatedByName { get; set; }
[JsonProperty("date_created")]
public string DateCreated { get; set; }
[JsonProperty("date_lost")]
public object DateLost { get; set; }
[JsonProperty("date_updated")]
public string DateUpdated { get; set; }
[JsonProperty("date_won")]
public object DateWon { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("integration_links")]
public object[] IntegrationLinks { get; set; }
[JsonProperty("lead_id")]
public string LeadId { get; set; }
[JsonProperty("lead_name")]
public string LeadName { get; set; }
[JsonProperty("note")]
public string Note { get; set; }
[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
[JsonProperty("status_id")]
public string StatusId { get; set; }
[JsonProperty("status_label")]
public string StatusLabel { get; set; }
[JsonProperty("status_type")]
public string StatusType { get; set; }
[JsonProperty("updated_by")]
public string UpdatedBy { get; set; }
[JsonProperty("updated_by_name")]
public string UpdatedByName { get; set; }
[JsonProperty("user_id")]
public string UserId { get; set; }
[JsonProperty("user_name")]
public string UserName { get; set; }
[JsonProperty("value")]
public long Value { get; set; }
[JsonProperty("value_currency")]
public string ValueCurrency { get; set; }
[JsonProperty("value_formatted")]
public string ValueFormatted { get; set; }
[JsonProperty("value_period")]
public string ValuePeriod { get; set; }
}
public partial class Custom
{
[JsonProperty("Date Created")]
public string DateCreated { get; set; }
[JsonProperty("Initial Service")]
public string InitialService { get; set; }
[JsonProperty("Lead Owner")]
public string LeadOwner { get; set; }
[JsonProperty("Marketing Source")]
public string MarketingSource { get; set; }
[JsonProperty("Location")]
public string Location { get; set; }
}
public class Email
{
[JsonProperty("email")]
public string EmailValue { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
}
public partial class Contact
{
[JsonProperty("created_by")]
public string CreatedBy { get; set; }
[JsonProperty("date_created")]
public string DateCreated { get; set; }
[JsonProperty("date_updated")]
public string DateUpdated { get; set; }
[JsonProperty("emails")]
public Email[] Emails { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("integration_links")]
public IntegrationLink[] IntegrationLinks { get; set; }
[JsonProperty("lead_id")]
public string LeadId { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
[JsonProperty("phones")]
public Phone[] Phones { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("updated_by")]
public string UpdatedBy { get; set; }
[JsonProperty("urls")]
public object[] Urls { get; set; }
}
public partial class Phone
{
[JsonProperty("phone_formatted")]
public string PhoneFormatted { get; set; }
[JsonProperty("phone")]
public string PhoneNumber { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
}
public partial class IntegrationLink
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
}
public partial class Welcome
{
public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, Converter.Settings);
}
In cases like this I find the query syntax more convenient than the fluent syntax, precisely because in nested SelectMany queries the outer items are accessible without needing to manually create intermediate anonymous types for passing values into the inner loop.
Thus:
var query = from d in json.Data
from c in d.Contacts
from e in c.Emails
select new { Email = e.EmailValue, LeadId = c.LeadId };
var emails = query.ToList();
This avoids the need to "go up" from the inner item to the outer.
Sample fiddle.

Using data from deserialized nested Json?

Here is my JSON:
{
"data": [
{
"addresses": [],
"contacts": [
{
"created_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"date_created": "2017-12-03T05:42:30.737000+00:00",
"date_updated": "2017-12-03T05:45:32.227000+00:00",
"emails": [
{
"email": "testemail#testemail.com",
"type": "office"
}
],
"id": "cont_kH9tcx970T3ZTGKPPP2vh5u3Ha8P9Rjz6gGqflgzwvy",
"integration_links": [
{
"name": "LinkedIn Search",
"url": "https://www.linkedin.com/search/results/index/?keywords=Test%20Woodard"
}
],
"lead_id": "lead_12Rz7R2TrWmwUhCGVTRh8rt6A8hokaXgujSEPlfoWpD",
"name": "Test User",
"organization_id": "orga_iFnIMLDbvGevDrXMHYQSbYnLu1GjrdM2TEWWsCoraJH",
"phones": [
{
"phone": "+15558675309",
"phone_formatted": "+1 555-867-5309",
"type": "office"
}
],
"title": "",
"updated_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"urls": []
}
],
"created_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"created_by_name": "Test User",
"custom": {
"Date Created": "2017-12-03",
"Initial Service": "Men's Health",
"Lead Owner": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"Marketing Source": "Bing"
},
"custom.lcf_UfNWMxg2f7UU28rI9RAhTEAPWMyXU1UFZb5oNJEgR0K": "Bing",
"custom.lcf_dDtwGb41tpi8XkVMMgxdHxEJ92A7ujreRU1aPPZd95B": "Chiropractor",
"custom.lcf_fUNjcSq8bemwdQL0wogc3wgyxmz3ZD17fKdv8s4wkWV": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"custom.lcf_y37bo72LesrOBWuVPSoRfIazw5KflujnV81nGCfcjZ3": "2017-12-03",
"date_created": "2017-12-03T05:42:30.733000+00:00",
"date_updated": "2017-12-03T05:45:32.234000+00:00",
"description": "",
"display_name": "test",
"html_url": "https://app.close.io/lead/lead_12Rz7R2TrWmwUhCFVTRh8rt6A8hokaXgujSEPlfoWpG/",
"id": "lead_12Rz7R2TrWmwUhCFVTRh8rt6A8hokaXgujSEPlfoWpD",
"integration_links": [
{
"name": "Google Search",
"url": "http://google.com/search?q=test"
}
],
"name": "test",
"opportunities": [
{
"confidence": 50,
"contact_id": null,
"contact_name": null,
"created_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"created_by_name": "Test User",
"date_created": "2017-12-03T05:44:31.131000+00:00",
"date_lost": null,
"date_updated": "2017-12-03T05:44:31.131000+00:00",
"date_won": null,
"id": "oppo_xQ5S1dHMjDWoeUBAigtyiwuwFUkxtbxHURQX5UaL7fT",
"integration_links": [],
"lead_id": "lead_12Rz7R2TrWmwUhCFVTRh8rt6A8hokaXgujSEPlfoWpD",
"lead_name": "test",
"note": "New Lead",
"organization_id": "orga_iFnIMLDbvNevDrXMHYQSbYnLu1GjrdM2TEWWsCoraJH",
"status_id": "stat_SwQmzqoIqIt20j9YBDxIYem11GyZPGL30G7PdkWYdvG",
"status_label": "Chiropractor",
"status_type": "active",
"updated_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"updated_by_name": "Test User",
"user_id": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"user_name": "Test User",
"value": 140000,
"value_currency": "USD",
"value_formatted": "$1,400",
"value_period": "one_time"
}
],
"organization_id": "orga_iFnIMLDbvNevDrXMHYQSbYnLu1GjrdM2TEWWsCoraJH",
"status_id": "stat_auhCEJZNhaUnX9DHdrCaZ5r5mhpqxjfaE1hdwnPz6xx",
"status_label": "Potential",
"tasks": [],
"updated_by": "user_C8ptFaOBRGnsYadWFUZCRCYXRnuV5Ch8Lgr9LKXz7zG",
"updated_by_name": "Test User",
"url": null
}
],
"has_more": false,
"total_results": 1
}
My Classes:
public partial class Welcome
{
[JsonProperty("data")]
public Datum[] Data { get; set; }
[JsonProperty("has_more")]
public bool HasMore { get; set; }
[JsonProperty("total_results")]
public long TotalResults { get; set; }
}
public partial class Datum
{
[JsonProperty("addresses")]
public object[] Addresses { get; set; }
[JsonProperty("contacts")]
public Contact[] Contacts { get; set; }
[JsonProperty("created_by")]
public string CreatedBy { get; set; }
[JsonProperty("created_by_name")]
public string CreatedByName { get; set; }
[JsonProperty("custom")]
public Custom Custom { get; set; }
[JsonProperty("custom.lcf_dDtwGb41tpi8XkVMMgxdHxEJ92A7ujreRU1aPPZd95B")]
public string CustomInitialService { get; set; }
[JsonProperty("custom.lcf_fUNjcSq8bemwdQL0wogc3wgyxmz3ZD17fKdv8s4wkWV")]
public string CustomLeadOwner { get; set; }
[JsonProperty("custom.lcf_UfNWMxg2f7UU28rI9RAhTEAPWMyXU1UFZb5oNJEgR0K")]
public string CustomMarketingSource { get; set; }
[JsonProperty("custom.lcf_y37bo72LesrOBWuVPSoRfIazw5KflujnV81nGCfcjZ3")]
public string CustomDateCreated { get; set; }
[JsonProperty("date_created")]
public string DateCreated { get; set; }
[JsonProperty("date_updated")]
public string DateUpdated { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("display_name")]
public string DisplayName { get; set; }
[JsonProperty("html_url")]
public string HtmlUrl { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("integration_links")]
public IntegrationLink[] IntegrationLinks { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("opportunities")]
public Opportunity[] Opportunities { get; set; }
[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
[JsonProperty("status_id")]
public string StatusId { get; set; }
[JsonProperty("status_label")]
public string StatusLabel { get; set; }
[JsonProperty("tasks")]
public object[] Tasks { get; set; }
[JsonProperty("updated_by")]
public string UpdatedBy { get; set; }
[JsonProperty("updated_by_name")]
public string UpdatedByName { get; set; }
[JsonProperty("url")]
public object Url { get; set; }
}
public partial class Opportunity
{
[JsonProperty("confidence")]
public long Confidence { get; set; }
[JsonProperty("contact_id")]
public object ContactId { get; set; }
[JsonProperty("contact_name")]
public object ContactName { get; set; }
[JsonProperty("created_by")]
public string CreatedBy { get; set; }
[JsonProperty("created_by_name")]
public string CreatedByName { get; set; }
[JsonProperty("date_created")]
public string DateCreated { get; set; }
[JsonProperty("date_lost")]
public object DateLost { get; set; }
[JsonProperty("date_updated")]
public string DateUpdated { get; set; }
[JsonProperty("date_won")]
public object DateWon { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("integration_links")]
public object[] IntegrationLinks { get; set; }
[JsonProperty("lead_id")]
public string LeadId { get; set; }
[JsonProperty("lead_name")]
public string LeadName { get; set; }
[JsonProperty("note")]
public string Note { get; set; }
[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
[JsonProperty("status_id")]
public string StatusId { get; set; }
[JsonProperty("status_label")]
public string StatusLabel { get; set; }
[JsonProperty("status_type")]
public string StatusType { get; set; }
[JsonProperty("updated_by")]
public string UpdatedBy { get; set; }
[JsonProperty("updated_by_name")]
public string UpdatedByName { get; set; }
[JsonProperty("user_id")]
public string UserId { get; set; }
[JsonProperty("user_name")]
public string UserName { get; set; }
[JsonProperty("value")]
public long Value { get; set; }
[JsonProperty("value_currency")]
public string ValueCurrency { get; set; }
[JsonProperty("value_formatted")]
public string ValueFormatted { get; set; }
[JsonProperty("value_period")]
public string ValuePeriod { get; set; }
}
public partial class Custom
{
[JsonProperty("Date Created")]
public string DateCreated { get; set; }
[JsonProperty("Initial Service")]
public string InitialService { get; set; }
[JsonProperty("Lead Owner")]
public string LeadOwner { get; set; }
[JsonProperty("Marketing Source")]
public string MarketingSource { get; set; }
}
public partial class Contact
{
[JsonProperty("created_by")]
public string CreatedBy { get; set; }
[JsonProperty("date_created")]
public string DateCreated { get; set; }
[JsonProperty("date_updated")]
public string DateUpdated { get; set; }
[JsonProperty("emails")]
public object[] Emails { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("integration_links")]
public IntegrationLink[] IntegrationLinks { get; set; }
[JsonProperty("lead_id")]
public string LeadId { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
[JsonProperty("phones")]
public Phone[] Phones { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("updated_by")]
public string UpdatedBy { get; set; }
[JsonProperty("urls")]
public object[] Urls { get; set; }
}
public partial class Phone
{
[JsonProperty("phone_formatted")]
public string PhoneFormatted { get; set; }
[JsonProperty("phone")]
public string PurplePhone { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
}
public partial class IntegrationLink
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
}
public partial class Welcome
{
public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this Welcome self) => JsonConvert.SerializeObject(self, Converter.Settings);
}
public class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
};
}
My Code:
var json = JsonConvert.DeserializeObject<Welcome>(html);
foreach (var j in json.Data)
{
foreach (var v in j.Contacts)
{
Console.WriteLine(v.Emails[0]);
}
}
So once I've deserialized the object I've tried using LINQ to get the email address out of the JSON using the objects, I can't navigate that far in and I'm not sure what's the best cleanest way to navigate for emails and phone numbers in the deserialized JSON.
First, for some reason you did not define a data model for your Email data:
public partial class Contact
{
// Initial properties
[JsonProperty("emails")]
public object[] Emails { get; set; }
// Additional properties.
Let's fix that with help from https://jsonutils.com/:
public partial class Contact
{
// Initial properties as before.
[JsonProperty("emails")]
public Email[] Emails { get; set; }
// Other properties as before
}
public class Email
{
[JsonProperty("email")]
public string EmailValue { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
}
Now you can iterate through all email and phone values by using SelectMany to create a final list:
var emails = json
// Enumerate through all data
.Data
// Enumerate through all contacts of all data
.SelectMany(d => d.Contacts)
// Enumerate through all emails of all contacts
.SelectMany(c => c.Emails)
// Get email value
.Select(e => e.EmailValue)
// Materialize as a list.
.ToList();
And
var phones = json
// Enumerate through all data
.Data
// Enumerate through all contacts of all data
.SelectMany(d => d.Contacts)
// Enumerate through all phones of all contacts
.SelectMany(c => c.Phones)
// Get phone number. But why ever did you choose to call it PurplePhone!?
.Select(p => p.PurplePhone)
// Materialize as a list.
.ToList();
Then, if you do:
Console.WriteLine("Emails: {0}", JsonConvert.SerializeObject(emails));
Console.WriteLine("Phones: {0}", JsonConvert.SerializeObject(phones));
The result is
Emails: ["testemail#testemail.com"]
Phones: ["+15558675309"]
Sample fiddle.

Json DeserializeObject return null - what i am doing wrong?

Here is the call to DeserializeObject:
listrootobject obj = JsonConvert.DeserializeObject<listrootobject>(json);
Here is Json .
{
"so:MemberProfileDataSet": {
"#xmlns:moso": "http://schema.socloud.com/1/MemberProfileDataSet.xsd",
"Member": {
"#xmlns": "http://schema.socloud.com/1/MemberProfileDataSet.xsd",
"PartyId": "63",
"PartyTypeName": "Employee",
"RoleId": "1310",
"BusinessUnitCode": "95",
"CardId": null,
"PostalContact": {
"PartyId": "63",
"TypeName": "Mailing Address",
"Address1": "100 Main Ave",
"Address2": null,
"Address3": null,
"City": "Arlington",
"State": "VA",
"PostalCode": "22206"
},
"PhoneContact": [{
"PartyId": "63",
"TypeName": "Cell",
"CountryCode": "1",
"Telephone": "(555) 555-5555",
"AdditionalData": null,
"TextMessageOK": "false"
}, {
"PartyId": "63",
"TypeName": "Home",
"CountryCode": "1",
"Telephone": null,
"AdditionalData": null,
"TextMessageOK": "false"
}],
"Property": [{
"PartyId": "63",
"Name": "First Name",
"Value": "Katie"
}, {
"PartyId": "63",
"Name": "Last Name",
"Value": "Rodriguez"
}, {
"PartyId": "63",
"Name": "Payroll ID",
"Value": null
}, {
"PartyId": "63",
"Name": "Lookup Initials",
"Value": null
}, {
"PartyId": "63",
"Name": "Date of Birth",
"Value": null
}, {
"PartyId": "63",
"Name": "Hire Date",
"Value": null
}, {
"PartyId": "63",
"Name": "Termination Date",
"Value": null
}, {
"PartyId": "63",
"Name": "Gender",
"Value": null
}]
}
}
}
Here is C# Class
public class PostalContact
{
public string PartyId { get; set; }
public string TypeName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
}
public class EmailContact
{
public string PartyId { get; set; }
public string TypeName { get; set; }
public string EmailAddress { get; set; }
public string EmailOptOut { get; set; }
}
public class PhoneContact
{
public string PartyId { get; set; }
public string TypeName { get; set; }
public string CountryCode { get; set; }
public string Telephone { get; set; }
public string AdditionalData { get; set; }
public string TextMessageOK { get; set; }
}
public class Property
{
public string PartyId { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
//public class rootobject
//{
// public List<Member> Members { get; set; }
//}
public class Member
{
public string PartyId { get; set; }
public string PartyTypeName { get; set; }
public string RoleId { get; set; }
public string BusinessUnitCode { get; set; }
public string CardId { get; set; }
public PostalContact PostalContact { get; set; }
public EmailContact EmailContact { get; set; }
public List<PhoneContact> PhoneContact { get; set; }
public List<Property> Property { get; set; }
public string _xmlns { get; set; }
}
public class MemberProfileDataSet
{
public Member Member { get; set; }
public string __invalid_name___xmlns_moso { get; set; }
public string __prefix { get; set; }
}
public class listrootobject
{
public List<MemberProfileDataSet> rootobjects { get; set; }
}
public class rootobject
{
public MemberProfileDataSet MemberProfileDataSet { get; set; }
}
Use http://json2csharp.com/ to generate and write your C# classes as the generated classes from the website. Lastly you parse the rootObject as below.
But you have a problem because the property names it generates are invalid in C# and you cannot create a C# class with those names. But the names must match to de-serialize. So you need to remove the invalid characters or re-name them to meet the C# CLR naming requirements.Then create a C# class of the properly formatted string. After which you can de-serialized.
For instance I generated C# object from the original string and I had a property name as
public SoMemberProfileDataSet __invalid_name__so:MemberProfileDataSet { get; set; }
This is invalid in C# but you would need to format this in the string to something valid e.g.
public SoMemberProfileDataSet MemberProfileDataSet { get; set; }
by renaming the json string or getting the properties you want from the string and re-constructing the json properly before de serializing.
Show me the code
As an example, I have combined strings between colons and removed the # symbol so that I created a valid C# object. And it de-seralizes. Please see changes in the json string below. So please format your json string and you will have it.
string json = "{\"soMemberProfileDataSet\": {\"xmlnsmoso\": \"http://schema.socloud.com/1/MemberProfileDataSet.xsd\",\"Member\": {\"xmlns\": \"http://schema.socloud.com/1/MemberProfileDataSet.xsd\",\"PartyId\": \"63\",\"PartyTypeName\": \"Employee\",\"RoleId\": \"1310\",\"BusinessUnitCode\": \"95\",\"CardId\": null,\"PostalContact\": {\"PartyId\": \"63\",\"TypeName\": \"Mailing Address\",\"Address1\": \"100 Main Ave\",\"Address2\": null,\"Address3\": null,\"City\": \"Arlington\",\"State\": \"VA\",\"PostalCode\": \"22206\"},\"PhoneContact\": [{\"PartyId\": \"63\",\"TypeName\": \"Cell\",\"CountryCode\": \"1\",\"Telephone\": \"(555) 555-5555\",\"AdditionalData\": null,\"TextMessageOK\": \"false\"}, {\"PartyId\": \"63\",\"TypeName\": \"Home\",\"CountryCode\": \"1\",\"Telephone\": null,\"AdditionalData\": null,\"TextMessageOK\": \"false\"}],\"Property\": [{\"PartyId\": \"63\",\"Name\": \"First Name\",\"Value\": \"Katie\"}, {\"PartyId\": \"63\",\"Name\": \"Last Name\",\"Value\": \"Rodriguez\"}, {\"PartyId\": \"63\",\"Name\": \"Payroll ID\",\"Value\": null}, {\"PartyId\": \"63\",\"Name\": \"Lookup Initials\",\"Value\": null}, {\"PartyId\": \"63\",\"Name\": \"Date of Birth\",\"Value\": null}, {\"PartyId\": \"63\",\"Name\": \"Hire Date\",\"Value\": null}, {\"PartyId\": \"63\",\"Name\": \"Termination Date\",\"Value\": null}, {\"PartyId\": \"63\",\"Name\": \"Gender\",\"Value\": null}]}}}";
var listrootobject = JsonConvert.DeserializeObject<RootObject>(json);
Your class should now look like as below, no more invalid property names after formatting
public class PostalContact
{
public string PartyId { get; set; }
public string TypeName { get; set; }
public string Address1 { get; set; }
public object Address2 { get; set; }
public object Address3 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
}
public class PhoneContact
{
public string PartyId { get; set; }
public string TypeName { get; set; }
public string CountryCode { get; set; }
public string Telephone { get; set; }
public object AdditionalData { get; set; }
public string TextMessageOK { get; set; }
}
public class Property
{
public string PartyId { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
public class Member
{
public string xmlns { get; set; }
public string PartyId { get; set; }
public string PartyTypeName { get; set; }
public string RoleId { get; set; }
public string BusinessUnitCode { get; set; }
public object CardId { get; set; }
public PostalContact PostalContact { get; set; }
public List<PhoneContact> PhoneContact { get; set; }
public List<Property> Property { get; set; }
}
public class SoMemberProfileDataSet
{
public string xmlnsmoso { get; set; }
public Member Member { get; set; }
}
public class RootObject
{
public SoMemberProfileDataSet soMemberProfileDataSet { get; set; }
}

Categories

Resources