T
T
TechNOIR2018-04-06 15:31:28
JSON
TechNOIR, 2018-04-06 15:31:28

C#. How to get values ​​from given JSON?

Good afternoon.
There is this JSON:

{
    "joined": {
        "@user1": {
            "avatar_url": null,
            "display_name": "user1"
        },
        "@user2": {
            "avatar_url": null,
            "display_name": "user2"
        }
    }
}

Created classes for online decentralization:
public partial class RoomUser
{
    public Dictionary<string, Joined> Joined { get; set; }
}

public partial class Joined
{
    public string AvatarUrl { get; set; }
    public string DisplayName { get; set; }
}

var room = JsonConvert.DeserializeObject<RoomUser>(fb.DownloadString(uri));

Joined includes "@user1" and "@user2". How would I get a list of what is included in Joined (in this case, 2 objects user1 and user2)?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
basrach, 2018-04-06
@basrach

Add attributes with the name of the fields, like this:

public partial class Joined
{
  [JsonProperty("avatar_url")]
  public string AvatarUrl { get; set; }
  [JsonProperty("display_name")]
  public string DisplayName { get; set; }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question