I've been searching for a while for a nice and clean way to convert a JSON object to a dynamic object.
(I could cast to an object but the Twitter Streaming API actually sends two different JSON objects with the possibility of future object types!)
The code I use currently is from:
Deserialize JSON into C# dynamic object?
But its not the cleanest code and I was playing around with Web Matrix and noticed that they have a nice JSON.Decode(string) and JSON.Encode(object) methods and wanted to make use of them.
http://msdn.microsoft.com/en-us/library/system.web.helpers.json(v=vs.99).aspx
Adding a reference to System.Web.Helpers to my C# console application I managed to compile a solution calling JSON.Decode but... it throws a nasty exception.
This is probably down to me using it in a way not intended (outside Web Matrix) but any ideas? Probably expecting a simple, no thats silly answer ;-)
Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed.
I'm using VS2010.
More detail: System.FieldAccessException was caught Message=Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed. Source=System.Web.Helpers StackTrace: at System.Web.Helpers.Json.Decode(String value) at Components.DataCollection.ConvertTwitterStream.ConvertTweets() in C:\Users\Administrator\documents\visual studio 2010\Projects\ISMM\Components\DataCollection\ConvertTwitterStream.cs:line 35 InnerException: