I have json that looks like:
myjson = {"queries":{"F.SP": 27}}
so with
queryResults = JObject.Parse(jsonString)
I can do
firstToken = queryResults.SelectToken("queries")
and get back the LinqJToken
{"F.SP": 27}
but I'm then stuck, because when I try
subToken = firstToken.SelectToken("F.SP")
I get Nothing. I'm guessing this is because JSON.net is looking for a token "F" with subtoken "SP".
I've also tried each of the following, to no avail
myToken = queryResults.SelectToken("queries.F.SP")
myToken = queryResults.SelectToken("queries[0].F.SP")
(queryResults.SelectToken("queries[0]") returns nothing, fwiw)
Any ideas?
EDIT: I have verified that the embedded "." is the problem; if I change the original json to
{"queries":{"FSP": 27}}
I can do
queryResults.SelectToken("queries").SelectToken("FSP")
no problem
If you have such names in JSON fields:
{"queries":{"F.SP": 27}}
You may use SelectToken escaping:
queryResults.SelectToken("queries").SelectToken("['F.SP']")
or
queryResults.SelectToken("queries.['F.SP']")
Here are more examples with escaping: http://www.newtonsoft.com/json/help/html/QueryJsonSelectTokenEscaped.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With