以前用 Fiddler.WebFormats,JSON.JsonDecode ,2025年更新后用不了了,这是官方的回应网页。
下面是我试出来的能用的代码,前面的部分已经发到他们官方论坛上去了。
今天遇到了数组没法获取长度的问题,发现需要换成 JArray 对象才行。又新找了如何进行格式转换。
结果他官方把帖子给锁了,我发表不了新内容了,目的就是为了让你用收费的 Fiddler EveryWhere。
//@assembly Newtonsoft.Json
import Newtonsoft.Json.Linq;
//Place the above two lines of code at the top of the CustomizeRules.js
//显示转换用
import Microsoft.JScript
static function OnBeforeResponse(oSession: Session) {
try {
// Get response body JSON string
var responseBody = oSession.GetResponseBodyAsString();
// Use Newtonsoft.Json Parse JSON
var jsonObject = JObject.Parse(responseBody);
// Get some field in JSON
var info = jsonObject["info"];
FiddlerApplication.Log.LogFormat("The exist info: {0}", info);
// Modify a field in the JSON
jsonObject["message"] = "Some New String.";
//如果要处理 JSON 里的数组,需要这样进行转换
var cards = Microsoft.JScript.Convert.CoerceT(jsonObject["card"], JArray , true);
FiddlerObject.alert("Cards 的数量为: " + cards.Count);
// Rewrite the modified JSON to the request body
oSession.utilSetResponseBody(jsonObject.ToString());
} catch (e) {
FiddlerObject.alert("JSON Parse Failed: " + e.Message);
}
}
115

被折叠的 条评论
为什么被折叠?



