最近刚接触JavaScript, 求帮解释一下下面现这两句。
sr="var s=" & Mid(strText, InStr(strText, "{"), Len(strText) - InStr(strText, "{")) & ";var st='';for(var y in s.result[0]){st+=s.result[0][y]+'\r';}"
eva = .eval(sr)
我把sr这个字符串的内容分解了一下:
var s="一段截取的字符串";
var st='';
for(var y in s.result[0]){st+=s.result[0][y]+'\r';}
不理解这个for 循环的用法, 还有eval的结果是从哪来的?我的意思是s,还是st? 我对eval得到正确的结果很想不明白,请大神给指导一下。
strText中的内容大致如下:(乱码位置为中文,请忽略不计)
jsonpCallback9710540({"actionErrors":[],"actionMessages":[],"errorMessages":[],"errors":{},"fieldErrors":{},"isPagination":"false","jsonCallBack":"jsonpCallback9710540","locale":"en_US","pageHelp":{"beginPage":1,"cacheSize":5,"data":null,"endDate":null,"endPage":null,"objectResult":null,"pageCount":null,"pageNo":1,"pageSize":10,"searchDate":null,"sort":null,"startDate":null,"total":0},"result":[{"WARRANTOR":"-","ENTERPRISE":"01ÈýÏ¿Õ®","RATING_AGENCY":"-","LISTING_CODE":"120102","TIME_LIMIT":"15","LISTING_DATE":"2002-04-19","BOND_RATING_AGENCY":"-","ISSUED_START_DAY":"2001-11-08","ISSUED_VOLUME":"30","FACE_VALUE":"100","WARRANTOR_WAY":"-","RATING_DATE":"-","ACCRUAL_METHOD":"1","BOND_RATING_DATE":"-","INTEREST_RATE":"5.21","DEBTOR":"Öйú³¤½­ÈýÏ¿¹¤³Ì¿ª·¢×ܹ«Ë¾","BOND_COLLATERAL_CODE":"-","BOND_CREDIT_LEVEL":"-","EXPIRY_DATE":"2016-11-08","INTEREST_RATE_DESC":"-","INDUSTRY":"-","CREDIT_LEVEL":"AAA","ACCRUAL_METHOD_DESC":"°´Ä긶Ϣ"}],"sqlId":"COMMON_SSE_ZQPZ_ZQ_GQ_GSZQYZJBXX_C","texts":null,"type":"","validateCod
e":""})
sr="var s=" & Mid(strText, InStr(strText, "{"), Len(strText) - InStr(strText, "{")) & ";var st='';for(var y in s.result[0]){st+=s.result[0][y]+'\r';}"
eva = .eval(sr)
我把sr这个字符串的内容分解了一下:
var s="一段截取的字符串";
var st='';
for(var y in s.result[0]){st+=s.result[0][y]+'\r';}
不理解这个for 循环的用法, 还有eval的结果是从哪来的?我的意思是s,还是st? 我对eval得到正确的结果很想不明白,请大神给指导一下。
strText中的内容大致如下:(乱码位置为中文,请忽略不计)
jsonpCallback9710540({"actionErrors":[],"actionMessages":[],"errorMessages":[],"errors":{},"fieldErrors":{},"isPagination":"false","jsonCallBack":"jsonpCallback9710540","locale":"en_US","pageHelp":{"beginPage":1,"cacheSize":5,"data":null,"endDate":null,"endPage":null,"objectResult":null,"pageCount":null,"pageNo":1,"pageSize":10,"searchDate":null,"sort":null,"startDate":null,"total":0},"result":[{"WARRANTOR":"-","ENTERPRISE":"01ÈýÏ¿Õ®","RATING_AGENCY":"-","LISTING_CODE":"120102","TIME_LIMIT":"15","LISTING_DATE":"2002-04-19","BOND_RATING_AGENCY":"-","ISSUED_START_DAY":"2001-11-08","ISSUED_VOLUME":"30","FACE_VALUE":"100","WARRANTOR_WAY":"-","RATING_DATE":"-","ACCRUAL_METHOD":"1","BOND_RATING_DATE":"-","INTEREST_RATE":"5.21","DEBTOR":"Öйú³¤½­ÈýÏ¿¹¤³Ì¿ª·¢×ܹ«Ë¾","BOND_COLLATERAL_CODE":"-","BOND_CREDIT_LEVEL":"-","EXPIRY_DATE":"2016-11-08","INTEREST_RATE_DESC":"-","INDUSTRY":"-","CREDIT_LEVEL":"AAA","ACCRUAL_METHOD_DESC":"°´Ä긶Ϣ"}],"sqlId":"COMMON_SSE_ZQPZ_ZQ_GQ_GSZQYZJBXX_C","texts":null,"type":"","validateCod
e":""})