Closed Flarescape closed 4 years ago
Maybe JToken.Parse()
would work ? https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_Linq_JToken_Parse.htm
Just tried it and it would work for this example, but I read that JToken is the base type so it's recommended to use JToken.Parse
.
https://www.newtonsoft.com/json/help/html/ParseJsonAny.htm
Ok, I think I never tested with using arrays directly, my original example was using an object ;) Submitting a PR
I just tried this example: https://docs.orchardcore.net/en/dev/docs/reference/modules/Liquid/#jsonparse 😄
Perfect, thank you. 👍
Thanks for noticing :)
OC RC2 13535 (latest dev)
The liquid example from the docs results in the following error, even if I remove the wrong comma:
JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
Update after some research: @jptissot You are using
JObject.Parse
right now, but if you use the example from the docs, it only works withJArray.Parse
, becauseJObject.Parse
is not the a universal parser for json strings.