1

I need the solution to convert json object to model if that object is number and i want to access the fields of that object.

{"threaded_extended": {
"857334186": [
  {
    "id": 871699994,
    "sender_id": 1621429355,
    "replied_to_id": 871550113,
    "created_at": "2017/04/07 09:45:18 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/871699994",
    "web_url": "https://www.yammer.com/kcc.com/messages/871699994",
    "group_id": 10601015,
    "body": {
      "parsed": "Test :)",
      "plain": "Test :)",
      "rich": "Test :)"
    },
    "thread_id": 857334186,
    "client_type": "Web",
    "client_url": "https://www.yammer.com/",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "Test :)"
  },
  {
    "id": 871550113,
    "sender_id": 1618001962,
    "replied_to_id": 857334186,
    "created_at": "2017/04/07 06:15:13 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/871550113",
    "web_url": "https://www.yammer.com/kcc.com/messages/871550113",
    "group_id": 10601015,
    "body": {
      "parsed": "QAhit",
      "plain": "QAhit",
      "rich": "QAhit"
    },
    "thread_id": 857334186,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "QAhit"
  }
],
"857334359": [
  {
    "id": 870871366,
    "sender_id": 1621195723,
    "replied_to_id": 857334359,
    "created_at": "2017/04/06 05:19:14 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/870871366",
    "web_url": "https://www.yammer.com/kcc.com/messages/870871366",
    "group_id": 10601015,
    "body": {
      "parsed": "asas",
      "plain": "asas",
      "rich": "asas"
    },
    "thread_id": 857334359,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "pt",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "asas"
  },
  {
    "id": 870476066,
    "sender_id": 1618001962,
    "replied_to_id": 857334359,
    "created_at": "2017/04/05 14:10:08 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/870476066",
    "web_url": "https://www.yammer.com/kcc.com/messages/870476066",
    "group_id": 10601015,
    "body": {
      "parsed": "test of gssmi",
      "plain": "test of gssmi",
      "rich": "test of gssmi"
    },
    "thread_id": 857334359,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "test of gssmi"
  }
],
"861760787": [
  {
    "id": 861906344,
    "sender_id": 1520171236,
    "replied_to_id": 861760787,
    "created_at": "2017/03/20 01:23:41 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/861906344",
    "web_url": "https://www.yammer.com/kcc.com/messages/861906344",
    "group_id": 10218161,
    "body": {
      "parsed": "this is nice!",
      "plain": "this is nice!",
      "rich": "this is nice!"
    },
    "thread_id": 861760787,
    "client_type": "Web",
    "client_url": "https://www.yammer.com/",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "this is nice!"
  },
  {
    "id": 861769267,
    "sender_id": 1618001962,
    "replied_to_id": 861760787,
    "created_at": "2017/03/19 13:08:53 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/861769267",
    "web_url": "https://www.yammer.com/kcc.com/messages/861769267",
    "group_id": 10218161,
    "body": {
      "parsed": "opened cm",
      "plain": "opened cm",
      "rich": "opened cm"
    },
    "thread_id": 861760787,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "opened cm"
  }
],
"862228666": [
  {
    "id": 863461826,
    "sender_id": 1527919854,
    "replied_to_id": 862228666,
    "created_at": "2017/03/22 18:32:36 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/863461826",
    "web_url": "https://www.yammer.com/kcc.com/messages/863461826",
    "group_id": 10218161,
    "body": {
      "parsed": "Looks great!",
      "plain": "Looks great!",
      "rich": "Looks great!"
    },
    "thread_id": 862228666,
    "client_type": "iPhone",
    "client_url": "https://about.yammer.com/product/mobile/ios/",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 1,
      "names": [
        {
          "full_name": "Karyn Prather (Yammer Admin)",
          "permalink": "karynlprather",
          "user_id": 1576848675,
          "network_id": 12467
        }
      ]
    },
    "content_excerpt": "Looks great!"
  },
  {
    "id": 863070068,
    "sender_id": 1618001962,
    "replied_to_id": 862228666,
    "created_at": "2017/03/22 03:20:18 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/863070068",
    "web_url": "https://www.yammer.com/kcc.com/messages/863070068",
    "group_id": 10218161,
    "body": {
      "parsed": "hi",
      "plain": "hi",
      "rich": "hi"
    },
    "thread_id": 862228666,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "hi"
  }
],
"863094568": [
  {
    "id": 884958709,
    "sender_id": 1553423930,
    "replied_to_id": 863094568,
    "created_at": "2017/05/05 08:08:57 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/884958709",
    "web_url": "https://www.yammer.com/kcc.com/messages/884958709",
    "group_id": 10218161,
    "body": {
      "parsed": "test1",
      "plain": "test1",
      "rich": "test1"
    },
    "thread_id": 863094568,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "test1"
  },
  {
    "id": 863094697,
    "sender_id": 1618001962,
    "replied_to_id": 863094568,
    "created_at": "2017/03/22 05:08:13 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/863094697",
    "web_url": "https://www.yammer.com/kcc.com/messages/863094697",
    "group_id": 10218161,
    "body": {
      "parsed": "testing",
      "plain": "testing",
      "rich": "testing"
    },
    "thread_id": 863094568,
    "client_type": "Web",
    "client_url": "https://www.yammer.com/",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "testing"
  }
],
"863094888": [
  {
    "id": 865647593,
    "sender_id": 1621195708,
    "replied_to_id": 863094888,
    "created_at": "2017/03/27 10:08:22 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/865647593",
    "web_url": "https://www.yammer.com/kcc.com/messages/865647593",
    "group_id": 10218161,
    "body": {
      "parsed": "hi test",
      "plain": "hi test",
      "rich": "hi test"
    },
    "thread_id": 863094888,
    "client_type": "Web",
    "client_url": "https://www.yammer.com/",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "hi test"
  },
  {
    "id": 863970308,
    "sender_id": 1621195708,
    "replied_to_id": 863094888,
    "created_at": "2017/03/23 13:30:37 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/863970308",
    "web_url": "https://www.yammer.com/kcc.com/messages/863970308",
    "group_id": 10218161,
    "body": {
      "parsed": "as",
      "plain": "as",
      "rich": "as"
    },
    "thread_id": 863094888,
    "client_type": "Web",
    "client_url": "https://www.yammer.com/",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "as"
  }
],
"864018272": [
  {
    "id": 884991311,
    "sender_id": 1553423930,
    "replied_to_id": 864018272,
    "created_at": "2017/05/05 09:26:43 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/884991311",
    "web_url": "https://www.yammer.com/kcc.com/messages/884991311",
    "group_id": 10218161,
    "body": {
      "parsed": "test",
      "plain": "test",
      "rich": "test"
    },
    "thread_id": 864018272,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "test"
  },
  {
    "id": 864779303,
    "sender_id": 1618001962,
    "replied_to_id": 864018272,
    "created_at": "2017/03/24 17:02:22 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/864779303",
    "web_url": "https://www.yammer.com/kcc.com/messages/864779303",
    "group_id": 10218161,
    "body": {
      "parsed": "Hi",
      "plain": "Hi",
      "rich": "Hi"
    },
    "thread_id": 864018272,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "nl",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "Hi"
  }
],
"864271024": [
  {
    "id": 887247097,
    "sender_id": 1621429355,
    "replied_to_id": 864271024,
    "created_at": "2017/05/10 13:35:29 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/887247097",
    "web_url": "https://www.yammer.com/kcc.com/messages/887247097",
    "group_id": 10218161,
    "body": {
      "parsed": "testing 567",
      "plain": "testing 567",
      "rich": "testing 567"
    },
    "thread_id": 864271024,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "testing 567"
  },
  {
    "id": 864577480,
    "sender_id": 1618001962,
    "replied_to_id": 864271024,
    "created_at": "2017/03/24 10:54:12 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/864577480",
    "web_url": "https://www.yammer.com/kcc.com/messages/864577480",
    "group_id": 10218161,
    "body": {
      "parsed": "fghj",
      "plain": "fghj",
      "rich": "fghj"
    },
    "thread_id": 864271024,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "fghj"
  }
],
"864742245": [
  {
    "id": 884920337,
    "sender_id": 1553423930,
    "replied_to_id": 864742245,
    "created_at": "2017/05/05 06:32:44 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/884920337",
    "web_url": "https://www.yammer.com/kcc.com/messages/884920337",
    "group_id": 10218161,
    "body": {
      "parsed": "test",
      "plain": "test",
      "rich": "test"
    },
    "thread_id": 864742245,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "test"
  }
],
"864822591": [
  {
    "id": 884937275,
    "sender_id": 1553423930,
    "replied_to_id": 864822591,
    "created_at": "2017/05/05 07:16:42 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/884937275",
    "web_url": "https://www.yammer.com/kcc.com/messages/884937275",
    "group_id": 10218161,
    "body": {
      "parsed": "tst",
      "plain": "tst",
      "rich": "tst"
    },
    "thread_id": 864822591,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "tst"
  },
  {
    "id": 869653071,
    "sender_id": 1618001962,
    "replied_to_id": 864822591,
    "created_at": "2017/04/04 06:49:34 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/869653071",
    "web_url": "https://www.yammer.com/kcc.com/messages/869653071",
    "group_id": 10218161,
    "body": {
      "parsed": "Hey",
      "plain": "Hey",
      "rich": "Hey"
    },
    "thread_id": 864822591,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "Hey"
  }
],
"865755084": [
  {
    "id": 884921126,
    "sender_id": 1553423930,
    "replied_to_id": 865755084,
    "created_at": "2017/05/05 06:35:12 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/884921126",
    "web_url": "https://www.yammer.com/kcc.com/messages/884921126",
    "group_id": 10218161,
    "body": {
      "parsed": "test",
      "plain": "test",
      "rich": "test"
    },
    "thread_id": 865755084,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 0,
      "names": []
    },
    "content_excerpt": "test"
  },
  {
    "id": 866548919,
    "sender_id": 1618001962,
    "replied_to_id": 865755084,
    "created_at": "2017/03/28 20:31:57 +0000",
    "network_id": 12467,
    "message_type": "update",
    "sender_type": "user",
    "url": "https://www.yammer.com/api/v1/messages/866548919",
    "web_url": "https://www.yammer.com/kcc.com/messages/866548919",
    "group_id": 10218161,
    "body": {
      "parsed": "test",
      "plain": "test",
      "rich": "test"
    },
    "thread_id": 865755084,
    "client_type": "K-C Way of Brand Building",
    "client_url": "https://kc-way.com",
    "system_message": false,
    "direct_message": false,
    "chat_client_sequence": null,
    "language": "en",
    "notified_user_ids": [],
    "privacy": "public",
    "attachments": [],
    "liked_by": {
      "count": 1,
      "names": [
        {
          "full_name": "Robert Visconti",
          "permalink": "robertvisconti",
          "user_id": 1527919854,
          "network_id": 12467
        }
      ]
    },
    "content_excerpt": "test"
  }
]
}}

please provide the solution how to convert this json into a model all the objects in the threaded_extended are in number formate

Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
nagulu vemula
  • 119
  • 1
  • 10
  • but here the object is dynamic it will changes may i know how to convert this – nagulu vemula May 12 '17 at 05:15
  • Is it just the first part that's dynamic? It would help if you'd provide some minimal examples of the JSON - we don't need 700 lines of JSON, most of which is *not* dynamic. – Jon Skeet May 12 '17 at 05:54

3 Answers3

1

Select all your Json data and Copy it. Then in Visual Studio follow this

Edit > Paste Special > Paste JSON as Classes

then all needed class will be generated automatically.

enter image description here

But make sure your json format should be a correct one.

Community
  • 1
  • 1
Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
  • i know how to deserialize it but the objects are generated like numbers it will change dynamically – nagulu vemula May 12 '17 at 05:22
  • This is not deserialization. This is creating the model from the json data. If you mean every time your model may change then you'd better to use `dynamic` type and forget the model classes. – Hossein Narimani Rad May 12 '17 at 05:24
  • Nice feature. Didn't know about this. Thanks. However I don't think it answers the question – Mick May 12 '17 at 05:51
1

Your question is somewhat unclear, but I suspect I see the pattern - the value of threaded_extended is effectively a Dictionary<int, List<Post>> or similar. So that's how you should represent it:

public class Root
{
    [JsonProperty("threaded_extended")]
    public Dictionary<int, List<Post>> ThreadedExtended { get; set; } 
}

public class Post
{        
    [JsonProperty("id")]
    public int Id { get; set; }
    [JsonProperty("sender_id")]
    public int SenderId { get; set; }
    // etc
}

You should then be able to deserialize your JSON into a Root:

Root root = JsonConvert.DeserializeObject<Root>(json);
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

OK so the two solutions you need to link together are...

  1. This stack overflow answer will help you create an object of type dynamic:

Deserialize json object into dynamic object using Json.net

  1. If you don't know what the properties on the dynamic object will be then you can use the following answer to iterate through the properties of the dynamic object to obtain the names of the properties and/or their values

How do I iterate over the properties of an anonymous object in C#?

Community
  • 1
  • 1
Mick
  • 6,527
  • 4
  • 52
  • 67