title: C# JSON decoding using Web Matrix helpers
body: <p>I've been searching for a while for a nice and clean way to convert a JSON object to a dynamic object.</p>
  
  <p>(I could cast to an object but the Twitter Streaming API actually sends two different JSON objects with the possibility of future object types!)</p>
  
  <p>The code I use currently is from:</p>
  
  <p><a href="https://stackoverflow.com/questions/3142495/deserialize-json-into-c-dynamic-object/3806407">Deserialize JSON into C# dynamic object?</a></p>
  
  <p>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.</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.web.helpers.json(v=vs.99).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.web.helpers.json(v=vs.99).aspx</a></p>
  
  <p>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.</p>
  
  <p>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 ;-)</p>
  
  <p>Attempt by method 'System.Web.Helpers.Json.Decode(System.String)' to access field 'System.Web.Helpers.Json._serializer' failed.</p>
  
  <hr>
  
  <p>I'm using VS2010.</p>
  
  <p>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: </p>