JSON to C# Class different key [closed]












-2















{  
"subscriptionId":"d56accdf-47eb-405c-b8fa-3b6577a52992",
"objectId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"objectType":"Group",
"eventType":"ActionResponse",
"eventId":"e2641057-1cc8-42f2-83ad-aae75b32ff1d",
"data":{
"actionId":"c0414e3f-44a8-4377-afe5-6047ba367b3c",
"actionPackageId":"com.microsoft.kaizala.miniapps.attendanceCard.GA",
"packageId":"com.microsoft.kaizala.miniapps.attendanceCard.GA",
"groupId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"sourceGroupId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"responseId":"e2641057-1cc8-42f2-83ad-aae75b32ff1d",
"isUpdateResponse":false,
"responder":"+919998902575",
"responderId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"creatorId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"responderName":"Piyush Kanpariya",
"responderProfilePic":"https://cdn.inc-000.kms.osi.office.net/usr/7318c832e091260306a2a10b99edb225a35efd8ba2ba0c0383017911f06923f8.jpg",
"isAnonymous":false,
"responseDetails":{
"responseWithQuestions":[
{
"title":"You can respond to this survey multiple times. To remember each response, you can give it any name or leave it as-is below.",
"type":"Text",
"options":[
],
"answer":"Response 1"
},
{
"title":"Responder Location",
"type":"Location",
"options":[
],
"answer":{
"lt":23.0509208,
"lg":72.4897822,
"n":"14, Thaltej Rd, Thaltej, Ahmedabad, Gujarat 380058, India",
"acc":31.843000411987305
}
},
{
"isInvisible":true,
"title":"ResponseTime",
"type":"DateTime",
"options":[

],
"answer":1546246937008
},
{
"title":"PhotoQuestionTitle",
"type":"Image",
"options":[

],
"answer":"https://cdn.inc-000.kms.osi.office.net/att/80461cf6ceb4e206664d0c88488d2c0618ce1d5147c215b0ebef6593aaa32554.jpg?sv=2015-12-11&sr=b&sig=5VfNHctjVTh0RenZjhRtGP%2Byu5cBNwuUFINPB4pMekU%3D&st=2018-12-31T08:02:18Z&se=2292-10-15T09:02:18Z&sp=r"
},
{
"title":"NotesQuestionTitle",
"type":"Text",
"options":[

],
"answer":"Goooo"
}
]
},
"Properties":[
{
"n":"DateTime",
"t":1,
"v":"2"
},
{
"n":"locationOrPhotoSettingText",
"v":"With Photo and Location"
},
{
"n":"locationOrPhotoSettingIcon",
"v":"photoWithLocationIcon.png"
},
{
"n":"expiryDateProperty",
"v":"Till Mon, 31 Dec, 23:59"
}
]
},
"context":"Any data which is required to be returned in callback. Current webhook data can be seen by refreshing: https://requestb.in/12786un1?inspect",
"fromUser":"+91XXXXXXXXXX",
"fromUserId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"isBotfromUser":false,
"fromUserName":"XYZ",
"fromUserProfilePic":"https://cdn.inc-000.kms.osi.office.net/usr/7318c832e091260306a2a10b99edb225a35efd8ba2ba0c0383017911f06923f8.jpg"
}









share|improve this question















closed as unclear what you're asking by n0rd, Zohar Peled, Robert Harvey Jan 1 at 6:17


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    There is no question here, can you perhaps specifically explain what you want, or whats not working

    – Michael Randall
    Jan 1 at 5:25








  • 1





    What is exactly the question ?

    – Mohamad Armoon
    Jan 1 at 5:25






  • 1





    What is your question? Could you please share what you need with us?

    – Julo
    Jan 1 at 5:26













  • This is a valid JSON. You can use the Visual Studio Edit -> Paste Special -> Paste JSON as classes tool to convert this object to C# classes, if that is the question.

    – Jimi
    Jan 1 at 5:31
















-2















{  
"subscriptionId":"d56accdf-47eb-405c-b8fa-3b6577a52992",
"objectId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"objectType":"Group",
"eventType":"ActionResponse",
"eventId":"e2641057-1cc8-42f2-83ad-aae75b32ff1d",
"data":{
"actionId":"c0414e3f-44a8-4377-afe5-6047ba367b3c",
"actionPackageId":"com.microsoft.kaizala.miniapps.attendanceCard.GA",
"packageId":"com.microsoft.kaizala.miniapps.attendanceCard.GA",
"groupId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"sourceGroupId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"responseId":"e2641057-1cc8-42f2-83ad-aae75b32ff1d",
"isUpdateResponse":false,
"responder":"+919998902575",
"responderId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"creatorId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"responderName":"Piyush Kanpariya",
"responderProfilePic":"https://cdn.inc-000.kms.osi.office.net/usr/7318c832e091260306a2a10b99edb225a35efd8ba2ba0c0383017911f06923f8.jpg",
"isAnonymous":false,
"responseDetails":{
"responseWithQuestions":[
{
"title":"You can respond to this survey multiple times. To remember each response, you can give it any name or leave it as-is below.",
"type":"Text",
"options":[
],
"answer":"Response 1"
},
{
"title":"Responder Location",
"type":"Location",
"options":[
],
"answer":{
"lt":23.0509208,
"lg":72.4897822,
"n":"14, Thaltej Rd, Thaltej, Ahmedabad, Gujarat 380058, India",
"acc":31.843000411987305
}
},
{
"isInvisible":true,
"title":"ResponseTime",
"type":"DateTime",
"options":[

],
"answer":1546246937008
},
{
"title":"PhotoQuestionTitle",
"type":"Image",
"options":[

],
"answer":"https://cdn.inc-000.kms.osi.office.net/att/80461cf6ceb4e206664d0c88488d2c0618ce1d5147c215b0ebef6593aaa32554.jpg?sv=2015-12-11&sr=b&sig=5VfNHctjVTh0RenZjhRtGP%2Byu5cBNwuUFINPB4pMekU%3D&st=2018-12-31T08:02:18Z&se=2292-10-15T09:02:18Z&sp=r"
},
{
"title":"NotesQuestionTitle",
"type":"Text",
"options":[

],
"answer":"Goooo"
}
]
},
"Properties":[
{
"n":"DateTime",
"t":1,
"v":"2"
},
{
"n":"locationOrPhotoSettingText",
"v":"With Photo and Location"
},
{
"n":"locationOrPhotoSettingIcon",
"v":"photoWithLocationIcon.png"
},
{
"n":"expiryDateProperty",
"v":"Till Mon, 31 Dec, 23:59"
}
]
},
"context":"Any data which is required to be returned in callback. Current webhook data can be seen by refreshing: https://requestb.in/12786un1?inspect",
"fromUser":"+91XXXXXXXXXX",
"fromUserId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"isBotfromUser":false,
"fromUserName":"XYZ",
"fromUserProfilePic":"https://cdn.inc-000.kms.osi.office.net/usr/7318c832e091260306a2a10b99edb225a35efd8ba2ba0c0383017911f06923f8.jpg"
}









share|improve this question















closed as unclear what you're asking by n0rd, Zohar Peled, Robert Harvey Jan 1 at 6:17


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    There is no question here, can you perhaps specifically explain what you want, or whats not working

    – Michael Randall
    Jan 1 at 5:25








  • 1





    What is exactly the question ?

    – Mohamad Armoon
    Jan 1 at 5:25






  • 1





    What is your question? Could you please share what you need with us?

    – Julo
    Jan 1 at 5:26













  • This is a valid JSON. You can use the Visual Studio Edit -> Paste Special -> Paste JSON as classes tool to convert this object to C# classes, if that is the question.

    – Jimi
    Jan 1 at 5:31














-2












-2








-2








{  
"subscriptionId":"d56accdf-47eb-405c-b8fa-3b6577a52992",
"objectId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"objectType":"Group",
"eventType":"ActionResponse",
"eventId":"e2641057-1cc8-42f2-83ad-aae75b32ff1d",
"data":{
"actionId":"c0414e3f-44a8-4377-afe5-6047ba367b3c",
"actionPackageId":"com.microsoft.kaizala.miniapps.attendanceCard.GA",
"packageId":"com.microsoft.kaizala.miniapps.attendanceCard.GA",
"groupId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"sourceGroupId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"responseId":"e2641057-1cc8-42f2-83ad-aae75b32ff1d",
"isUpdateResponse":false,
"responder":"+919998902575",
"responderId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"creatorId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"responderName":"Piyush Kanpariya",
"responderProfilePic":"https://cdn.inc-000.kms.osi.office.net/usr/7318c832e091260306a2a10b99edb225a35efd8ba2ba0c0383017911f06923f8.jpg",
"isAnonymous":false,
"responseDetails":{
"responseWithQuestions":[
{
"title":"You can respond to this survey multiple times. To remember each response, you can give it any name or leave it as-is below.",
"type":"Text",
"options":[
],
"answer":"Response 1"
},
{
"title":"Responder Location",
"type":"Location",
"options":[
],
"answer":{
"lt":23.0509208,
"lg":72.4897822,
"n":"14, Thaltej Rd, Thaltej, Ahmedabad, Gujarat 380058, India",
"acc":31.843000411987305
}
},
{
"isInvisible":true,
"title":"ResponseTime",
"type":"DateTime",
"options":[

],
"answer":1546246937008
},
{
"title":"PhotoQuestionTitle",
"type":"Image",
"options":[

],
"answer":"https://cdn.inc-000.kms.osi.office.net/att/80461cf6ceb4e206664d0c88488d2c0618ce1d5147c215b0ebef6593aaa32554.jpg?sv=2015-12-11&sr=b&sig=5VfNHctjVTh0RenZjhRtGP%2Byu5cBNwuUFINPB4pMekU%3D&st=2018-12-31T08:02:18Z&se=2292-10-15T09:02:18Z&sp=r"
},
{
"title":"NotesQuestionTitle",
"type":"Text",
"options":[

],
"answer":"Goooo"
}
]
},
"Properties":[
{
"n":"DateTime",
"t":1,
"v":"2"
},
{
"n":"locationOrPhotoSettingText",
"v":"With Photo and Location"
},
{
"n":"locationOrPhotoSettingIcon",
"v":"photoWithLocationIcon.png"
},
{
"n":"expiryDateProperty",
"v":"Till Mon, 31 Dec, 23:59"
}
]
},
"context":"Any data which is required to be returned in callback. Current webhook data can be seen by refreshing: https://requestb.in/12786un1?inspect",
"fromUser":"+91XXXXXXXXXX",
"fromUserId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"isBotfromUser":false,
"fromUserName":"XYZ",
"fromUserProfilePic":"https://cdn.inc-000.kms.osi.office.net/usr/7318c832e091260306a2a10b99edb225a35efd8ba2ba0c0383017911f06923f8.jpg"
}









share|improve this question
















{  
"subscriptionId":"d56accdf-47eb-405c-b8fa-3b6577a52992",
"objectId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"objectType":"Group",
"eventType":"ActionResponse",
"eventId":"e2641057-1cc8-42f2-83ad-aae75b32ff1d",
"data":{
"actionId":"c0414e3f-44a8-4377-afe5-6047ba367b3c",
"actionPackageId":"com.microsoft.kaizala.miniapps.attendanceCard.GA",
"packageId":"com.microsoft.kaizala.miniapps.attendanceCard.GA",
"groupId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"sourceGroupId":"17d936e3-f96c-4752-8cdc-ffa9b3437ee9",
"responseId":"e2641057-1cc8-42f2-83ad-aae75b32ff1d",
"isUpdateResponse":false,
"responder":"+919998902575",
"responderId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"creatorId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"responderName":"Piyush Kanpariya",
"responderProfilePic":"https://cdn.inc-000.kms.osi.office.net/usr/7318c832e091260306a2a10b99edb225a35efd8ba2ba0c0383017911f06923f8.jpg",
"isAnonymous":false,
"responseDetails":{
"responseWithQuestions":[
{
"title":"You can respond to this survey multiple times. To remember each response, you can give it any name or leave it as-is below.",
"type":"Text",
"options":[
],
"answer":"Response 1"
},
{
"title":"Responder Location",
"type":"Location",
"options":[
],
"answer":{
"lt":23.0509208,
"lg":72.4897822,
"n":"14, Thaltej Rd, Thaltej, Ahmedabad, Gujarat 380058, India",
"acc":31.843000411987305
}
},
{
"isInvisible":true,
"title":"ResponseTime",
"type":"DateTime",
"options":[

],
"answer":1546246937008
},
{
"title":"PhotoQuestionTitle",
"type":"Image",
"options":[

],
"answer":"https://cdn.inc-000.kms.osi.office.net/att/80461cf6ceb4e206664d0c88488d2c0618ce1d5147c215b0ebef6593aaa32554.jpg?sv=2015-12-11&sr=b&sig=5VfNHctjVTh0RenZjhRtGP%2Byu5cBNwuUFINPB4pMekU%3D&st=2018-12-31T08:02:18Z&se=2292-10-15T09:02:18Z&sp=r"
},
{
"title":"NotesQuestionTitle",
"type":"Text",
"options":[

],
"answer":"Goooo"
}
]
},
"Properties":[
{
"n":"DateTime",
"t":1,
"v":"2"
},
{
"n":"locationOrPhotoSettingText",
"v":"With Photo and Location"
},
{
"n":"locationOrPhotoSettingIcon",
"v":"photoWithLocationIcon.png"
},
{
"n":"expiryDateProperty",
"v":"Till Mon, 31 Dec, 23:59"
}
]
},
"context":"Any data which is required to be returned in callback. Current webhook data can be seen by refreshing: https://requestb.in/12786un1?inspect",
"fromUser":"+91XXXXXXXXXX",
"fromUserId":"dd1df3da-64bd-4c4c-b18f-99c9279da1f2",
"isBotfromUser":false,
"fromUserName":"XYZ",
"fromUserProfilePic":"https://cdn.inc-000.kms.osi.office.net/usr/7318c832e091260306a2a10b99edb225a35efd8ba2ba0c0383017911f06923f8.jpg"
}






c# json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 5:25









Robert Harvey

149k33275419




149k33275419










asked Jan 1 at 5:20









Piyush KanpariyaPiyush Kanpariya

36




36




closed as unclear what you're asking by n0rd, Zohar Peled, Robert Harvey Jan 1 at 6:17


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by n0rd, Zohar Peled, Robert Harvey Jan 1 at 6:17


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2





    There is no question here, can you perhaps specifically explain what you want, or whats not working

    – Michael Randall
    Jan 1 at 5:25








  • 1





    What is exactly the question ?

    – Mohamad Armoon
    Jan 1 at 5:25






  • 1





    What is your question? Could you please share what you need with us?

    – Julo
    Jan 1 at 5:26













  • This is a valid JSON. You can use the Visual Studio Edit -> Paste Special -> Paste JSON as classes tool to convert this object to C# classes, if that is the question.

    – Jimi
    Jan 1 at 5:31














  • 2





    There is no question here, can you perhaps specifically explain what you want, or whats not working

    – Michael Randall
    Jan 1 at 5:25








  • 1





    What is exactly the question ?

    – Mohamad Armoon
    Jan 1 at 5:25






  • 1





    What is your question? Could you please share what you need with us?

    – Julo
    Jan 1 at 5:26













  • This is a valid JSON. You can use the Visual Studio Edit -> Paste Special -> Paste JSON as classes tool to convert this object to C# classes, if that is the question.

    – Jimi
    Jan 1 at 5:31








2




2





There is no question here, can you perhaps specifically explain what you want, or whats not working

– Michael Randall
Jan 1 at 5:25







There is no question here, can you perhaps specifically explain what you want, or whats not working

– Michael Randall
Jan 1 at 5:25






1




1





What is exactly the question ?

– Mohamad Armoon
Jan 1 at 5:25





What is exactly the question ?

– Mohamad Armoon
Jan 1 at 5:25




1




1





What is your question? Could you please share what you need with us?

– Julo
Jan 1 at 5:26







What is your question? Could you please share what you need with us?

– Julo
Jan 1 at 5:26















This is a valid JSON. You can use the Visual Studio Edit -> Paste Special -> Paste JSON as classes tool to convert this object to C# classes, if that is the question.

– Jimi
Jan 1 at 5:31





This is a valid JSON. You can use the Visual Studio Edit -> Paste Special -> Paste JSON as classes tool to convert this object to C# classes, if that is the question.

– Jimi
Jan 1 at 5:31












2 Answers
2






active

oldest

votes


















0














use http://json2csharp.com/



public class ResponseWithQuestion
{
public string title { get; set; }
public string type { get; set; }
public List<object> options { get; set; }
public object answer { get; set; }
public bool? isInvisible { get; set; }
}

public class ResponseDetails
{
public List<ResponseWithQuestion> responseWithQuestions { get; set; }
}

public class Property
{
public string n { get; set; }
public int t { get; set; }
public string v { get; set; }
}

public class Data
{
public string actionId { get; set; }
public string actionPackageId { get; set; }
public string packageId { get; set; }
public string groupId { get; set; }
public string sourceGroupId { get; set; }
public string responseId { get; set; }
public bool isUpdateResponse { get; set; }
public string responder { get; set; }
public string responderId { get; set; }
public string creatorId { get; set; }
public string responderName { get; set; }
public string responderProfilePic { get; set; }
public bool isAnonymous { get; set; }
public ResponseDetails responseDetails { get; set; }
public List<Property> Properties { get; set; }
}

public class RootObject
{
public string subscriptionId { get; set; }
public string objectId { get; set; }
public string objectType { get; set; }
public string eventType { get; set; }
public string eventId { get; set; }
public Data data { get; set; }
public string context { get; set; }
public string fromUser { get; set; }
public string fromUserId { get; set; }
public bool isBotfromUser { get; set; }
public string fromUserName { get; set; }
public string fromUserProfilePic { get; set; }
}


try convert answer property to intended type by TryParse Method






share|improve this answer

































    0














    I use this static method to get property values from json and set into my class object:
    (add Newtonsoft.Json)



    public static string GetValObj(object obj, string propertyName)
    {
    if (obj is JContainer container)
    {
    var nsj = container.First;
    do
    {
    if (string.Equals(nsj.Path, propertyName, StringComparison.CurrentCultureIgnoreCase))
    {
    if (((JValue)((JProperty)nsj).Value).Value == null)
    return string.Empty;
    return ((JValue)((JProperty)nsj).Value).Value
    .ToString();
    }

    nsj = nsj.Next;
    } while (nsj != null);
    }

    return obj.GetType().GetProperty(propertyName).GetValue(obj, null).ToString();
    }





    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      use http://json2csharp.com/



      public class ResponseWithQuestion
      {
      public string title { get; set; }
      public string type { get; set; }
      public List<object> options { get; set; }
      public object answer { get; set; }
      public bool? isInvisible { get; set; }
      }

      public class ResponseDetails
      {
      public List<ResponseWithQuestion> responseWithQuestions { get; set; }
      }

      public class Property
      {
      public string n { get; set; }
      public int t { get; set; }
      public string v { get; set; }
      }

      public class Data
      {
      public string actionId { get; set; }
      public string actionPackageId { get; set; }
      public string packageId { get; set; }
      public string groupId { get; set; }
      public string sourceGroupId { get; set; }
      public string responseId { get; set; }
      public bool isUpdateResponse { get; set; }
      public string responder { get; set; }
      public string responderId { get; set; }
      public string creatorId { get; set; }
      public string responderName { get; set; }
      public string responderProfilePic { get; set; }
      public bool isAnonymous { get; set; }
      public ResponseDetails responseDetails { get; set; }
      public List<Property> Properties { get; set; }
      }

      public class RootObject
      {
      public string subscriptionId { get; set; }
      public string objectId { get; set; }
      public string objectType { get; set; }
      public string eventType { get; set; }
      public string eventId { get; set; }
      public Data data { get; set; }
      public string context { get; set; }
      public string fromUser { get; set; }
      public string fromUserId { get; set; }
      public bool isBotfromUser { get; set; }
      public string fromUserName { get; set; }
      public string fromUserProfilePic { get; set; }
      }


      try convert answer property to intended type by TryParse Method






      share|improve this answer






























        0














        use http://json2csharp.com/



        public class ResponseWithQuestion
        {
        public string title { get; set; }
        public string type { get; set; }
        public List<object> options { get; set; }
        public object answer { get; set; }
        public bool? isInvisible { get; set; }
        }

        public class ResponseDetails
        {
        public List<ResponseWithQuestion> responseWithQuestions { get; set; }
        }

        public class Property
        {
        public string n { get; set; }
        public int t { get; set; }
        public string v { get; set; }
        }

        public class Data
        {
        public string actionId { get; set; }
        public string actionPackageId { get; set; }
        public string packageId { get; set; }
        public string groupId { get; set; }
        public string sourceGroupId { get; set; }
        public string responseId { get; set; }
        public bool isUpdateResponse { get; set; }
        public string responder { get; set; }
        public string responderId { get; set; }
        public string creatorId { get; set; }
        public string responderName { get; set; }
        public string responderProfilePic { get; set; }
        public bool isAnonymous { get; set; }
        public ResponseDetails responseDetails { get; set; }
        public List<Property> Properties { get; set; }
        }

        public class RootObject
        {
        public string subscriptionId { get; set; }
        public string objectId { get; set; }
        public string objectType { get; set; }
        public string eventType { get; set; }
        public string eventId { get; set; }
        public Data data { get; set; }
        public string context { get; set; }
        public string fromUser { get; set; }
        public string fromUserId { get; set; }
        public bool isBotfromUser { get; set; }
        public string fromUserName { get; set; }
        public string fromUserProfilePic { get; set; }
        }


        try convert answer property to intended type by TryParse Method






        share|improve this answer




























          0












          0








          0







          use http://json2csharp.com/



          public class ResponseWithQuestion
          {
          public string title { get; set; }
          public string type { get; set; }
          public List<object> options { get; set; }
          public object answer { get; set; }
          public bool? isInvisible { get; set; }
          }

          public class ResponseDetails
          {
          public List<ResponseWithQuestion> responseWithQuestions { get; set; }
          }

          public class Property
          {
          public string n { get; set; }
          public int t { get; set; }
          public string v { get; set; }
          }

          public class Data
          {
          public string actionId { get; set; }
          public string actionPackageId { get; set; }
          public string packageId { get; set; }
          public string groupId { get; set; }
          public string sourceGroupId { get; set; }
          public string responseId { get; set; }
          public bool isUpdateResponse { get; set; }
          public string responder { get; set; }
          public string responderId { get; set; }
          public string creatorId { get; set; }
          public string responderName { get; set; }
          public string responderProfilePic { get; set; }
          public bool isAnonymous { get; set; }
          public ResponseDetails responseDetails { get; set; }
          public List<Property> Properties { get; set; }
          }

          public class RootObject
          {
          public string subscriptionId { get; set; }
          public string objectId { get; set; }
          public string objectType { get; set; }
          public string eventType { get; set; }
          public string eventId { get; set; }
          public Data data { get; set; }
          public string context { get; set; }
          public string fromUser { get; set; }
          public string fromUserId { get; set; }
          public bool isBotfromUser { get; set; }
          public string fromUserName { get; set; }
          public string fromUserProfilePic { get; set; }
          }


          try convert answer property to intended type by TryParse Method






          share|improve this answer















          use http://json2csharp.com/



          public class ResponseWithQuestion
          {
          public string title { get; set; }
          public string type { get; set; }
          public List<object> options { get; set; }
          public object answer { get; set; }
          public bool? isInvisible { get; set; }
          }

          public class ResponseDetails
          {
          public List<ResponseWithQuestion> responseWithQuestions { get; set; }
          }

          public class Property
          {
          public string n { get; set; }
          public int t { get; set; }
          public string v { get; set; }
          }

          public class Data
          {
          public string actionId { get; set; }
          public string actionPackageId { get; set; }
          public string packageId { get; set; }
          public string groupId { get; set; }
          public string sourceGroupId { get; set; }
          public string responseId { get; set; }
          public bool isUpdateResponse { get; set; }
          public string responder { get; set; }
          public string responderId { get; set; }
          public string creatorId { get; set; }
          public string responderName { get; set; }
          public string responderProfilePic { get; set; }
          public bool isAnonymous { get; set; }
          public ResponseDetails responseDetails { get; set; }
          public List<Property> Properties { get; set; }
          }

          public class RootObject
          {
          public string subscriptionId { get; set; }
          public string objectId { get; set; }
          public string objectType { get; set; }
          public string eventType { get; set; }
          public string eventId { get; set; }
          public Data data { get; set; }
          public string context { get; set; }
          public string fromUser { get; set; }
          public string fromUserId { get; set; }
          public bool isBotfromUser { get; set; }
          public string fromUserName { get; set; }
          public string fromUserProfilePic { get; set; }
          }


          try convert answer property to intended type by TryParse Method







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 1 at 5:40

























          answered Jan 1 at 5:34









          aliyanaliyan

          364




          364

























              0














              I use this static method to get property values from json and set into my class object:
              (add Newtonsoft.Json)



              public static string GetValObj(object obj, string propertyName)
              {
              if (obj is JContainer container)
              {
              var nsj = container.First;
              do
              {
              if (string.Equals(nsj.Path, propertyName, StringComparison.CurrentCultureIgnoreCase))
              {
              if (((JValue)((JProperty)nsj).Value).Value == null)
              return string.Empty;
              return ((JValue)((JProperty)nsj).Value).Value
              .ToString();
              }

              nsj = nsj.Next;
              } while (nsj != null);
              }

              return obj.GetType().GetProperty(propertyName).GetValue(obj, null).ToString();
              }





              share|improve this answer




























                0














                I use this static method to get property values from json and set into my class object:
                (add Newtonsoft.Json)



                public static string GetValObj(object obj, string propertyName)
                {
                if (obj is JContainer container)
                {
                var nsj = container.First;
                do
                {
                if (string.Equals(nsj.Path, propertyName, StringComparison.CurrentCultureIgnoreCase))
                {
                if (((JValue)((JProperty)nsj).Value).Value == null)
                return string.Empty;
                return ((JValue)((JProperty)nsj).Value).Value
                .ToString();
                }

                nsj = nsj.Next;
                } while (nsj != null);
                }

                return obj.GetType().GetProperty(propertyName).GetValue(obj, null).ToString();
                }





                share|improve this answer


























                  0












                  0








                  0







                  I use this static method to get property values from json and set into my class object:
                  (add Newtonsoft.Json)



                  public static string GetValObj(object obj, string propertyName)
                  {
                  if (obj is JContainer container)
                  {
                  var nsj = container.First;
                  do
                  {
                  if (string.Equals(nsj.Path, propertyName, StringComparison.CurrentCultureIgnoreCase))
                  {
                  if (((JValue)((JProperty)nsj).Value).Value == null)
                  return string.Empty;
                  return ((JValue)((JProperty)nsj).Value).Value
                  .ToString();
                  }

                  nsj = nsj.Next;
                  } while (nsj != null);
                  }

                  return obj.GetType().GetProperty(propertyName).GetValue(obj, null).ToString();
                  }





                  share|improve this answer













                  I use this static method to get property values from json and set into my class object:
                  (add Newtonsoft.Json)



                  public static string GetValObj(object obj, string propertyName)
                  {
                  if (obj is JContainer container)
                  {
                  var nsj = container.First;
                  do
                  {
                  if (string.Equals(nsj.Path, propertyName, StringComparison.CurrentCultureIgnoreCase))
                  {
                  if (((JValue)((JProperty)nsj).Value).Value == null)
                  return string.Empty;
                  return ((JValue)((JProperty)nsj).Value).Value
                  .ToString();
                  }

                  nsj = nsj.Next;
                  } while (nsj != null);
                  }

                  return obj.GetType().GetProperty(propertyName).GetValue(obj, null).ToString();
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 1 at 5:39









                  CodeManCodeMan

                  557311




                  557311















                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      Npm cannot find a required file even through it is in the searched directory