How to convert a JToken
You should use:
int totalDatas = tData.Value<Int32>();
You can use the JToken.ToObject<T>()
method.
JToken token = ...;
int value = token.ToObject<int>();
try this: int value = (int)token.Value;
You can simply cast the JToken
to int
:
string json = @"{totalDatas : ""1234""}";
JObject obj = JObject.Parse(json);
JToken token = obj["totalDatas"];
int result = (int)token;
//print 2468
Console.WriteLine(result*2);
[.NET fiddle demo]