I need to navigate a Json structure as I would navigate an XML using XmlDocument
.
The structure is not known, and I need to iterate over the nodes to parse some data.
Is this possible?
I know I can use JavaScriptSerializer
to deserialize it into a known type, but this is not the case as I can receive any valid json.
I'm using .NET 3.5 (SP1) and cannot upgrade to 4.0 at the moment.
I upgraded to .NET 4.0 to use dynamic types (which is awesomeness made code)
Read this article:
It explains you a way of parsing JSON to a dynamic object which has a dictionary inside.
So, iterating a dictionary would be nice with LINQ, wouldn't be?
--- OR IF YOU'RE IN .NET 3.5... --- ;)
Why don't you implement an extension method like "ToDictionary"?
You can receive JSON text, later parse with a regular expression and split properties and values into a dictionary, everything done with suggested extension method.
A sample of how it would work that:
IDictionary<string, object> deserializedJson = jsonText.ToDictionary();
Fits your needs?
--- EVEN YET ANOTHER TRY (now you've more options)! ---
Check this open source project on CodePlex:
It has LINQ-to-JSON so you can read and write JSON.
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