How to use Fiddler.WebFormats.JSON.JsonDecode

3 posts, 0 answers
  1. Arnaud
    Arnaud avatar
    2 posts
    Member since:
    Apr 2014

    Posted 08 Apr 2014 Link to this post

    Hello,

    I have a JSON string and I want to parse it to an object (to do some query after that).
    I have found Fiddler.WebFormats.JSON.JsonDecode() but the returned JSONObject has no method to get or set content.

    How to decode and use JSON strings ?

    Thanks for any help !
  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 08 Apr 2014 Link to this post

    Hello, Arnaud--

    The returned object has a JSONObject property which is an ArrayList, Hashtable, or primitive value that is equivalent to the json object in question. Fiddler uses this class in its JSONView extension.

    If you prefer a different pattern (e.g. something with strong typing, a schema, etc) then you can & should use one of the myriad JSON encoder/decoders available for the .NET Framework.

    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Arnaud
    Arnaud avatar
    2 posts
    Member since:
    Apr 2014

    Posted 09 Apr 2014 in reply to Eric Lawrence Link to this post

    Hello Eric,

    Thanks for your quick answer. My wrong was to miss JSONObject and its meaning.
    I post my test case (in FiddlerScript) in case someone has the same question:

    var sInput = '{"a" : 1, "b" : [2, 3, 4]}';
    var oJSON = Fiddler.WebFormats.JSON.JsonDecode(sInput);
    FiddlerApplication.Log.LogFormat('input: {0}', sInput);
    FiddlerApplication.Log.LogFormat('oJSON: {0}', oJSON.ToString());
    FiddlerApplication.Log.LogFormat('oJSON["a"]: {0} (expected: 1)', oJSON.JSONObject["a"]);
    FiddlerApplication.Log.LogFormat('oJSON["b"] : {0} (expected: 2)', oJSON.JSONObject["b"][0]);

Back to Top