-1
"user": {
  "1330789870659362817": {
    "id": "xxxxxxxxxxxxxxxxxx",
    "created_timestamp": "1606120016282",
    "name": "yyyyyyyyyyyyy",
    "screen_name": "wwwwwwwww",
    "protected": false,
    "verified": false,
    "followers_count": 9,
    "friends_count": 23,
    "statuses_count": 368,
    "profile_image_url": "qqqqqqqqqqqqqqqq",
    "profile_image_url_https": "sssssssss"
  },
  "1467799120933003275": {
    "id": "wwwwwwwww",
    "created_timestamp": "1638785572496",
    "name": "cccccccccccc",
    "screen_name": "xxxxxxxxxxxx",
    "location": "xxxxxxxx",
    "description": "Cricket",
    "protected": false,
    "verified": false,
    "followers_count": 1,
    "friends_count": 4,
    "statuses_count": 37,
    "profile_image_url": "xxxxxx",
    "profile_image_url_https": "xxxxxxxxx"
  }
}

I am expecting to Deserialize that json with a class every request should be acceptable when another request came with other number like _5838364784684847657

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
Umair Khan
  • 17
  • 2
  • Instead of using a class, you should just use the `JsonNode` Parse method as your JSON is not defined , or try to change the system that emits such JSON which is non-schema or non-type friendly. – Anand Sowmithiran Dec 30 '22 at 15:05

1 Answers1

1

you can deserialize to a RootObject object, which will have a dictionary as a member.

public class User
{
    public string id { get; set; }
    public string created_timestamp { get; set; }
    public string name { get; set; }
    public string screen_name { get; set; }
    public string location { get; set; }
    public string description { get; set; }
    public bool @protected { get; set; }
    public bool verified { get; set; }
    public int followers_count { get; set; }
    public int friends_count { get; set; }
    public int statuses_count { get; set; }
    public string profile_image_url { get; set; }
    public string profile_image_url_https { get; set; }
}

public class RootObject
{
    public Dictionary<string, User> user { get; set; }
}

I have used NewtonSoft.Json for deserialization.

var obj = JsonConvert.DeserializeObject<RootObject>(json);

foreach (var kvp in obj.user)
{
    string key = kvp.Key;
    User user = kvp.Value;
}
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197