[c#] Accessing all items in the JToken

I have a json block like this:


                "1":"United States"
            "name":"Floor Number",
            "name":"Address Map"

How can I get all the key items that this token includes. For example from the above code I want to have "ADRESS_LOCATION" , "LOCATION", "FLOOR_NUMBER" and "self".

This question is related to c# json json.net

The answer is

You can cast your JToken to a JObject and then use the Properties() method to get a list of the object properties. From there, you can get the names rather easily.

Something like this:

string json =

                ""1"":""United States""
            ""name"":""Floor Number"",
            ""name"":""Address Map""

JToken outer = JToken.Parse(json);
JObject inner = outer["ADDRESS_MAP"].Value<JObject>();

List<string> keys = inner.Properties().Select(p => p.Name).ToList();

foreach (string k in keys)



Similar questions with c# tag:

Similar questions with json tag:

Similar questions with json.net tag: