You don't really need to worry about JContainer in most cases. It is there to help organize and structure LINQ-to-JSON into well-factored code
The JToken hierarchy looks like this:
JToken - abstract base class
JContainer - abstract base class of JTokens that can contain other JTokens
JArray - represents a JSON array (contains an ordered list of JTokens)
JObject - represents a JSON object (contains a collection of JProperties)
JProperty - represents a JSON property (a name/JToken pair inside a JObject)
JValue
So you see, a JObject is a JContainer, which is a JToken.
Here's the basic rule of thumb:
- If you know you have an object (denoted by curly braces
{
and}
in JSON), use JObject - If you know you have an array or list (denoted by square brackets
[
and]
), use JArray - If you know you have a primitive value, use JValue
- If you don't know what kind of token you have, or want to be able to handle any of the above in a general way, use JToken. You can then check its
Type
property to determine what kind of token it is and cast it appropriately.