0

i somehow can´t reach the objects in a nested json. I easily can reach the element test, but how to reach this_month inside "stats"? this is my json:

{"test":"OK","stats":{"this_month":"1653","this_week":"1653"}}

this is my code inside the customrules.cs

        var oResponseBody = oSession.GetResponseBodyAsString();
        JSON.JSONParseResult oJSON = JSON.JsonDecode(oResponseBody) as JSON.JSONParseResult;
        Hashtable oObj = oJSON.JSONObject as Hashtable; 

        oObj["test"] = "changed";




         var modBytes = Fiddler.WebFormats.JSON.JsonEncode(oObj);

        // Convert json to bytes, storing the bytes in request body
        var mod = System.Text.Encoding.UTF8.GetBytes(modBytes);
        oSession.ResponseBody = mod; 

As soon as I want to acces this_month in "stats" with this: oObj["stats"]["this_month"] = "changed"; my fiddler get´s errors and crashes.

Denni
  • 25
  • 2
  • I'm not quite sure, but looks like you may need to cast, ie: `((Hashtable)oObj["stats"])["this_month"] = "somevalue";` – Ron Beyer Oct 03 '18 at 21:07
  • it works like this, but after changes the value it crashes again. there is some looping with this method what causes to crash i guess – Denni Oct 03 '18 at 21:24

0 Answers0