-
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); static 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提示错误”仅在类定义内有效“ -
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); static 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提示错误”仅在类定义内有效“这个错误提示通常是因为你在方法体之外访问了一个变量,或者在方法之外使用了一个方法调用。
具体来说,在你的代码中,错误出现在这里:
static var TM = responseJSON.JSONObject['data']['problems'][1]['answers'];
你应该将这行代码放在方法体内部,并且不要在变量名和分号之间放置空格,应该像这样:
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); } }
这应该可以解决你的问题。如果还有其他疑问,请随时问我。
-
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);
}
}FiddlerScrip输出为得到”undefined“不是数组数量
-
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); } } FiddlerScrip输出为”undefined“不是数组数量
-
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“不是数组数量根据您提供的代码,读取数组长度的代码
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);