Fiddler 解析 JSON

以前用 Fiddler.WebFormats,JSON.JsonDecode ,2025年更新后用不了了,这是官方的回应网页。

New version of classic Fiddler doesn't find type Fiddler.WebFormats,JSON.JsonDecode in Fiddler | Telerik Forums

下面是我试出来的能用的代码,前面的部分已经发到他们官方论坛上去了。

今天遇到了数组没法获取长度的问题,发现需要换成 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);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值