-
Mrfeng 说:
if(m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal);
var TM = responseJSON.JSONObject['data']['problems'][1]['answers']
var arrayLength = TM.Length;
FiddlerObject.log(arrayLength);
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}
@ChatGPT FiddlerScrip输出为”undefined“不是数组数量根据您提供的代码,读取数组长度的代码
var arrayLength = TM.Length;
似乎有问题。数组的长度应该使用.length
,并且 JS 中数组是区分大小写的,因此应该使用var arrayLength = TM.length;
。修改后的代码应该是这样的:
if(m_KPPT){ if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){ var responseStringOriginal = oSession.GetResponseBodyAsString(); var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal); var TM = responseJSON.JSONObject['data']['problems'][1]['answers']; var arrayLength = TM.length; FiddlerObject.log(arrayLength); var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject); oSession.utilSetResponseBody(responseStringDestinal); } }
这样,
FiddlerObject.log
内输出的就是正确的数组长度了。 -
if(m_KPPT){ if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){ var responseStringOriginal = oSession.GetResponseBodyAsString(); var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal); var TM = responseJSON.JSONObject['data']['problems'][1]['answers'] var arrayLength = TM.length; FiddlerObject.log(arrayLength); var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject); oSession.utilSetResponseBody(responseStringDestinal); } }
@ChatGPT FiddlerScrip输出为”undefined“不是数组数量
-
Mrfeng 说:
if(m_KPPT){ if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){ var responseStringOriginal = oSession.GetResponseBodyAsString(); var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal); var TM = responseJSON.JSONObject['data']['problems'][1]['answers'] var arrayLength = TM.length; FiddlerObject.log(arrayLength); var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject); oSession.utilSetResponseBody(responseStringDestinal); } }
@ChatGPT FiddlerScrip输出为”undefined“不是数组数量
可能是因为代码中的变量m_KPPT未被定义或者没有被初始化,导致if语句不成立,从而无法进入相应的代码块。请检查并确保变量m_KPPT的值已被正确设置。同时检查代码中其他变量是否也存在同样的问题。
-
public static RulesOption("123", "自定义开关") BindPref("fiddlerscript.rules.KPT") var m_KPPT: boolean = false; if(m_KPPT){ if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){ var responseStringOriginal = oSession.GetResponseBodyAsString(); var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal); var TM = responseJSON.JSONObject['data']['problems'] var arrayLength = TM.length; FiddlerObject.log(arrayLength); var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject); oSession.utilSetResponseBody(responseStringDestinal); } }
@ChatGPT FiddlerScrip输出为”undefined“不是数组数量
-
Mrfeng 说:
public static RulesOption("123", "自定义开关")
BindPref("fiddlerscript.rules.KPT")
var m_KPPT: boolean = false;
if(m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal);
var TM = responseJSON.JSONObject['data']['problems']
var arrayLength = TM.length;
FiddlerObject.log(arrayLength);
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}
@ChatGPT FiddlerScrip输出为”undefined“不是数组数量这个问题可能是因为在JSON解码过程中出现了错误。请尝试添加一些错误处理代码,以便在解码错误时输出错误信息。例如:
try { var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal); var TM = responseJSON.JSONObject['data']['problems'] var arrayLength = TM.length; FiddlerObject.log(arrayLength); var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject); oSession.utilSetResponseBody(responseStringDestinal); } catch (e) { FiddlerObject.log("Error decoding JSON: " + e.message); }
这样,如果解码过程中发生错误,您将能够看到错误消息并找出问题所在。
-
var m_KPPT: boolean = false;
if(m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal);
for (var i = 0; i < 10; i++) {
var myArray = responseJSON.JSONObject['data']['problems'][i]['answers'];
FiddlerObject.log(myArray);
}
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}@ChatGPT FiddlerScrip输出为”System.Collections.ArrayList“ 怎么输出文本
-
Mrfeng 说:
var m_KPPT: boolean = false;
if(m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal);
for (var i = 0; i var myArray = responseJSON.JSONObject['data']['problems'][i]['answers'];
FiddlerObject.log(myArray);
}
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}@ChatGPT FiddlerScrip输出为”System.Collections.ArrayList“ 怎么输出文本
你可以使用
JSON.stringify()
将结果转换为字符串,以便在 Fiddler Script 输出窗口中显示。更改代码如下:var m_KPPT: boolean = false; if (m_KPPT){ if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){ var responseStringOriginal = oSession.GetResponseBodyAsString(); var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal); for (var i = 0; i < 10; i++) { var myArray = responseJSON.JSONObject['data']['problems'][i]['answers']; FiddlerObject.log(JSON.stringify(myArray)); } var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject); oSession.utilSetResponseBody(responseStringDestinal); } }
这将在 Fiddler 输出窗口中显示可读的 JSON 字符串。
-
var m_KPPT: boolean = false;
if (m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal);
for (var i = 0; i < 10; i++) {
var myArray = responseJSON.JSONObject['data']['problems'][i]['answers'];
FiddlerObject.log(myArray.length);
}
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}
@ChatGPT FiddlerScrip myArray 是”System.Collections.ArrayList“ ,myArray.length输出为undefined,myArray.length怎能输出为数量 -
Mrfeng 说:
var m_KPPT: boolean = false;
if (m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal);
for (var i = 0; i var myArray = responseJSON.JSONObject['data']['problems'][i]['answers'];
FiddlerObject.log(myArray.length);
}
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}
@ChatGPT FiddlerScrip myArray 是”System.Collections.ArrayList“ ,myArray.length输出为undefined,myArray.length怎能输出为数量根据您提供的代码,您需要访问myArray中的长度,以及作为System.Collections.ArrayList对象,myArray.length应该返回该数组的元素数量。但是,由于JavaScript不是静态类型的语言,这意味着myArray变量的类型可能不是ArrayList,因此可能会出现undefined值。
如果要确保myArray的类型和长度都正确访问,您可以尝试以下更改:
var myArray = responseJSON.JSONObject['data']['problems'][i]['answers']; if (myArray instanceof Array) { FiddlerObject.log(myArray.length); }
在这里,我们添加了一个条件,检查myArray是否是一个数组。如果是,它应该返回正确的长度。如果myArray不是数组,我们将避免记录其长度并继续执行代码。
-
var m_KPPT: boolean = false;
if (m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal);
for (var i = 0; i var myArray = responseJSON.JSONObject['data']['problems'][i]['answers'];
FiddlerObject.log(myArray.length);
}
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}
@ChatGPT FiddlerScrip myArray 是数组 ,myArray.length输出为undefined,myArray.length怎能输出为数量 -
Mrfeng 说:
var m_KPPT: boolean = false;
if (m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(responseStringOriginal);
for (var i = 0; i var myArray = responseJSON.JSONObject['data']['problems'][i]['answers'];
FiddlerObject.log(myArray.length);
}
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}
@ChatGPT FiddlerScrip myArray 是数组 ,myArray.length输出为undefined,myArray.length怎能输出为数量可以尝试将代码改为以下形式:
var myArray = responseJSON.JSONObject['data']['problems'][i]['answers']; var count = Object.keys(myArray).length; FiddlerObject.log(count);
或者
var myArray = responseJSON.JSONObject['data']['problems'][i]['answers']; var count = myArray.length; FiddlerObject.log(count);
这样应该可以正确输出数组的长度。其中第一种方式使用
Object.keys()
来获取对象属性的数量,第二种方式使用了数组的length
属性。 -
var m_KPPT: boolean = false;
if(m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var ss =responseStringOriginal.ToString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(ss);
for (var i = 0; i < 10; i++) {
var myArray = responseJSON.JSONObject['data']['problems'][i]['answers'];
FiddlerObject.log(myArray[0]);
}
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}
@ChatGPT FiddlerScrip myArray 是数组 ,myArray.length输出为undefined,myArray[0]怎能输出为“System.Collections.Hashtable” -
Mrfeng 说:
var m_KPPT: boolean = false;
if(m_KPPT){
if (oSession.fullUrl.Contains("api.kpxf.kcshop.vip/activities/get-knowledge-problem?access-token")){
var responseStringOriginal = oSession.GetResponseBodyAsString();
var ss =responseStringOriginal.ToString();
var responseJSON = Fiddler.WebFormats.JSON.JsonDecode(ss);
for (var i = 0; i var myArray = responseJSON.JSONObject['data']['problems'][i]['answers'];
FiddlerObject.log(myArray[0]);
}
var responseStringDestinal = Fiddler.WebFormats.JSON.JsonEncode(responseJSON.JSONObject);
oSession.utilSetResponseBody(responseStringDestinal);
}
}
@ChatGPT FiddlerScrip myArray 是数组 ,myArray.length输出为undefined,myArray[0]怎能输出为“System.Collections.Hashtable”首先,通过观察代码可以发现,myArray并没有在使用前被声明和初始化赋值,它只是从responseJSON.JSONObject中某个对象中读取了一组值。
因此,myArray实际上是一个对象或哈希表(Hashtable),它存储了一组键值对,而不是数组。这也就是为什么myArray.length输出undefined的原因。
要访问myArray中的值,你需要使用对象或哈希表的方式,例如myArray[0]应该改为myArray["0"]。在这种情况下,myArray["0"]将返回与键"0"对应的值。
所以,如果要正确输出myArray的值,应该对代码进行如下修改:
for (var i = 0; i < 10; i++) { var myArray = responseJSON.JSONObject['data']['problems'][i]['answers']; FiddlerObject.log(myArray["0"]); // 通过myArray的键名来获取对应的值 }
-
Mrfeng 说:
@ChatGPT FiddlerScrip 中将数组对象转化为数组
举例几个以下是将数组对象转化为数组的示例:
- 将对象数组转为数字数组:
var objArr = [{ num: 1 }, { num: 2 }, { num: 3 }]; var numArr = objArr.map(obj => obj.num);
- 将对象数组转为字符串数组:
var objArr = [{ name: 'Alice' }, { name: 'Bob' }, { name: 'Charlie' }]; var nameArr = objArr.map(obj => obj.name);
- 将嵌套对象数组转为一维数组:
var objArr = [{ fruits: [{ name: 'Apple' }, { name: 'Banana' }] }, { fruits: [{ name: 'Orange' }, { name: 'Grape' }] }]; var fruitArr = objArr.flatMap(obj => obj.fruits.map(fruit => fruit.name));
- 将对象数组中的某个属性值转为数组:
var objArr = [{ name: 'Alice', hobbies: ['reading', 'swimming'] }, { name: 'Bob', hobbies: ['running', 'climbing'] }]; var hobbyArr = objArr.flatMap(obj => obj.hobbies);
-
Mrfeng 说:
@ChatGPT FiddlerScrip 中将System.Collections.ArrayList输出为数组
在 FiddlerScript 中,可以通过以下代码将 System.Collections.ArrayList 输出为数组:
var arrayList = new System.Collections.ArrayList(); // 填充 ArrayList var array = arrayList.ToArray();
在上面的示例中,先创建了一个 ArrayList 实例,并且填充了一些数据。然后通过调用
ToArray()
方法将 ArrayList 输出为数组。输出的数组的数据类型与 ArrayList 中存储的元素相同,并且它们的顺序也是一致的。 -
Mrfeng 说:
@ChatGPT FiddlerScrip 中将System.Collections.ArrayList的数量获取
要获取
System.Collections.ArrayList
中元素的数量,可以使用Count
属性。以下是一个在 FiddlerScript 中获取ArrayList.Count
的示例代码:// 获取响应Body中JSON数组元素数量 if (oSession.responseBodyBytes.Length > 0 && oSession.oResponse.headers.ExistsAndContains("Content-Type", "application/json")) { try { var responseString = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes); var jsonArray = Newtonsoft.Json.Linq.JArray.Parse(responseString) as System.Collections.ArrayList; var jsonArrayLength = jsonArray.Count; // 将jsonArrayLength 打印到Fiddler日志中 FiddlerApplication.Log.LogString($"Json Array Length: {jsonArrayLength}"); } catch (ex) { // 处理异常 } }
在此示例中,我们首先将响应Body中的JSON解析为
JArray
对象,并将其转化为ArrayList
类型。然后通过获取Count
属性获取整个ArrayList
的长度。最后,我们将jsonArrayLength
打印到 Fiddler 的日志中。