Json Array for String Array C #

2

I just need to get the names of the json moderators and viewers:

{
  "_links": {},
  "chatter_count": 16,
  "chatters": {
    "moderators": ["gumagames", "juliavidoto", "nightbot", "pinkpanthersz_", "victoriia66"],
    "staff": [],
    "admins": [],
    "global_mods": [],
    "viewers": ["andreschramm", "anotheruselessbot", "barbosza", "brancoxp", "froydz1515", "hurato2", "luiz522", "phoenixlabella", "rockmam", "sumarilion1988", "xoverxkill"]
  }
}

I'm using JSON.Net but I did not get a satisfactory result.

    
asked by anonymous 01.03.2016 / 22:05

2 answers

1

You need to create a class according to your Json, and after that just use:

JsonConvert.DeserializeObject<SeuObjeto>(stringJson);

That it will parse Json into its class and return the instantiated object.

Follow the fiddle .

Generating Json classes in C #: json2csharp

    
01.03.2016 / 23:31
0

Using the command line jq :

jq ".chatters.moderators,.chatters.viewers" ex.json

produces:

[
  "gumagames",
  "juliavidoto",
  "nightbot",
  "pinkpanthersz_",
  "victoriia66"
]
[
  "andreschramm",
  "anotheruselessbot",
  "barbosza",
  "brancoxp",
  "froydz1515",
  "hurato2",
  "luiz522",
  "phoenixlabella",
  "rockmam",
  "sumarilion1988",
  "xoverxkill"
]

or jq ".chatters.moderators+.chatters.viewers" to get a single array

    
01.03.2016 / 23:48