我正在尝试编写一个 FiddlerScript 来修改从服务器返回的 JSON 数组的属性。
这是我到目前为止所尝试的:
static function OnBeforeResponse(oSession: Session) {
if (m_Hide304s && oSession.responseCode == 304) {
oSession["ui-hide"] = "true";
}
if(oSession.HostnameIs("myserver.com") && oSession.uriContains("info")) {
oSession["ui-backcolor"] = "lime";
// Convert the request body into a string
var oBody = System.Text.Encoding.UTF8.GetString(oSession.requestBodyBytes);
// Convert the text into a JSON object
var j = Fiddler.WebFormats.JSON.JsonDecode(oBody);
var placementsArray = j.JSONObject["placements"];
FiddlerObject.log("Got Placements.");
// I can't figure out how to access the elements of the array
//for (var i: int=0; i < placementsArray.Length; i++) {
// placements[i]["isValid"] = true;
//}
// Convert back to a byte array
var modBytes = Fiddler.WebFormats.JSON.JsonEncode(j.JSONObject);
// Convert json to bytes, storing the bytes in request body
var mod = System.Text.Encoding.UTF8.GetBytes(modBytes);
oSession.RequestBody = mod;
}
}
我需要有关在此函数中间注释掉的 for 循环的帮助。我想遍历“放置”数组,然后在每个“放置”对象中更改一个名为“IsValid”的值。我需要这样做,以便我可以修改来自服务器的响应,以便我可以使用数组项属性值的不同服务器响应来测试客户端应用程序。