S
S
s33332019-08-17 00:38:46
JSON
s3333, 2019-08-17 00:38:46

I can't figure out how to parse json. How to properly deserialize it?

First time trying json. I can't figure out how to properly deserialize this

{"friendslist":{"friends":[{"steamid":"76561198031578776","relationship":"friend","friend_since":1519194870},{"steamid":"76561198040628535","relationship":"friend","friend_since":1460743289},{"steamid":"76561198064448781","relationship":"friend","friend_since":1455558965},{"steamid":"76561198104120440","relationship":"friend","friend_since":1519384031},{"steamid":"76561198109191269","relationship":"friend","friend_since":1504938002},{"steamid":"76561198110798041","relationship":"friend","friend_since":1447854941},{"steamid":"76561198127465790","relationship":"friend","friend_since":1453310591},{"steamid":"76561198133109575","relationship":"friend","friend_since":1519384077},{"steamid":"76561198145337568","relationship":"friend","friend_since":1467553994},{"steamid":"76561198159932861","relationship":"friend","friend_since":1521375098},{"steamid":"76561198244703782","relationship":"friend","friend_since":1453310526},{"steamid":"76561198254025285","relationship":"friend","friend_since":1456919535},{"steamid":"76561198309666523","relationship":"friend","friend_since":1469003976},{"steamid":"76561198340461418","relationship":"friend","friend_since":1533993583},{"steamid":"76561198371604483","relationship":"friend","friend_since":1502435448},{"steamid":"76561198828236470","relationship":"friend","friend_since":1540726616}]}}

Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ark Tarusov, 2019-08-17
@s3333

To deserialize json in c#, you need to use any plugin for working in json, as a newtonsoft
option. If you need to not just go over json, but also create classes, then there are services such as json2csharp
to automate this action. Here is the result from your json

public class Friend
{
    public string steamid { get; set; }
    public string relationship { get; set; }
    public int friend_since { get; set; }
}

public class Friendslist
{
    public List<Friend> friends { get; set; }
}

public class RootObject
{
    public Friendslist friendslist { get; set; }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question