Chrome扩展程序:未插入或提取数据

时间:2016-03-31 04:57:01

标签: javascript google-chrome-extension web-sql

我正在使用WebSQL。我试图在异步块中添加数据,这使得数据无法插入。代码如下:

{"data":[{"id":"1","title":"- Parts I & II”,”CODE”:”xxx”,”product_url":"http:\/\/www.example.com","image_url":"http:\/\/ecx.images-example.com\/images\/I\/61ujIIMyW7L.jpg","price":"$25.00"},{"id":"2","title”:”AJDJDDJDr”,”Code”:”XX”,”product_url":"http:\/\/www.example.com","image_url":"http:\/\/dc.images-example.com\/images\/I\/41jFVZL72YL.jpg","price":"$10.99"}]}

JSON转储

#include<iostream>


using namespace std;


int main(){

   int col, row,i;
   int **array;

   cout << "How many rows?\n";
   cin >> row;
   cout << "How many colomns\n";
   cin >> col;

cout << "!!!!!!!!!!!!";

   array = new int*[row];
   for (int i = 0;i<row;i++){
          array[i] = new int[col];
   }   

        cout << "!!!!!!!!!!!!";

   for( i=0; i<row; i++){
        int x=1;
      array[0][i]= x;; 
   x++;
   }   
        cout << "!!!!!!!!!!!!";
   cout << array[row][col];

   for(i=0; i<row; i++){

   delete [] array[i];
   delete [] array;
   }   
   return 0; 
}

1 个答案:

答案 0 :(得分:0)

试试这个;)

此循环条件出现问题:

for(var a = 0; a <= data.length; a++) {
                  ^

此处您从0开始并循环到data.length

所以要循环数组,因为数组索引从0循环开始直到a <= data.length - 1a < data.length

for(var a = 0; a < data.length; a++) {

OR

for(var a=0; a <= (data.length - 1); a++) {

您可以像for这样使用for...in而不是for(var index in data){ alert(data[index].title); } 循环:

;