需要帮助测试阵列上的数据

时间:2011-06-05 17:37:15

标签: jquery ajax json greasemonkey

我是GM的新人。 我遇到了阵列段的问题。这是代码:

var A1_rest= '';
var A1reset_go          = false;
var auctiontyp = 0

var myJson              = '{"d":[["","","y","ZAR","1","49517","6458, 8270, 8270, 8270, 7635",null,"1.40","6458","0:13:30","","12","","C","30",null],["y","-00:00","y","ZAR","2","49593","6458, 6458, 6458, 6458, 6458",null,"2.92","6458","0:13:37","","12","","L","12","Ve4mYdrvkkQMKxBH1\/1VMtDTCDQBRspg5jB8jjY08zg="],["","","y","ZAR","3","49058","7456, 9216, 6458, 5153, 7456",null,"194.40","7456","0:00:31","","1100","","T",null,null],["","","y","ZAR","4","49597","2935, 6554",null,"1.22","2935","0:01:16","","12","","T",null,null],["","","y","ZAR","5","49590","4440, 0518, 5343, 2625, 4848",null,"0.95","4440","0:15:58","","5","","L",null,null],["","","y","ZAR","6","49591","4848, 4440, 4440, 0518, 2625",null,"1.81","4848","0:16:05","","12","","L",null,null],["","","y","ZAR","7","49595","6458",null,"5.55","6458","0:04:13","","55","","T",null,null],["","","y","ZAR","8","49596","",null,"2.90","NONE","0:04:35","","29","","T",null,null],["","","y","ZAR","9","49496","6458, 2427, 2427, 7863, 5845",null,"2.56","6458","0:06:07","","10","","B",null,null],["","","y","ZAR","10","49524","6458, 2427, 7863, 7863, 5845",null,"1.67","6458","0:06:00","","5","","B",null,null],["","","y","ZAR","11","49539","6458, 2427, 7863, 7863, 0764",null,"2.02","6458","0:04:25","","10","","B",null,null]]}'
var jsonObj             = $.parseJSON (myJson);

//--- The JSON should return a 2-D array, named "d".
var arrayOfAuctions     = jsonObj.d;

//--- Loop over each row in the array.
$.each (
    arrayOfAuctions,
    function (rowIndex, singleAuctionData) {

        //--- Print the 7th column.
          console.log ('Row: ' + (parseInt (rowIndex) + 1) + ' Column: 7  Value: ' + singleAuctionData[6]);
  //up to here its fine


  auctiontyp=parseInt (singleAuctionData[4]);
   if (auctiontyp== 1)

     {

   A1_rest=singleAuctionData[16];
       alert(A1_rest);
       alert(singleAuctionData[16]);
        //2 alerts not the same...?
       if (A1_rest != 'null')
         {alert('doing incorrectly');
          A1reset_go=true;
          };
        else
          {alert('success1');
           }
       alert('check5.1');
       alert(A1reset_go);
       if (A1_rest == 'null') and (A1reset_go==true)
         {alert('should also not run but does');
          A1reset_go=false; 
          A1_start=singleAuctionData[8];
         };
         else 
         {alert('success2');
          };
    };

我当前的问题是:“A1_rest”和“singleAuctionData [16]”

我认为“singleAuctionData [16]”将是“null”的文本值,但它不是,它是一些其他值,但是,在警报时它给出“null”的输出。我不确定如何测试它。在这种情况下,在第一个段中的数组上(我测试)它应该执行“success1”和“success2”。在数组的第二段,如果我运行相同的测试,它应该只警告“做错误”和“success2”。 有人可以帮帮我吗?提前致谢。 路德维希

1 个答案:

答案 0 :(得分:1)

您期望“文本值为null”,但我认为实际值只是null,或者没有,而不是文本'null'