Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在react原生sqlite存储中存储json对象?_Json_Sqlite_React Native_Storage - Fatal编程技术网

如何在react原生sqlite存储中存储json对象?

如何在react原生sqlite存储中存储json对象?,json,sqlite,react-native,storage,Json,Sqlite,React Native,Storage,我是新来的。在将json数据存储到数据库表中时,我面临一个问题。我试图将json对象存储到表中,但出现错误 以下是我的json数据: let formData = {"inspection":{ "date":"23-11-2018", "client name" :"John Doe", "locations":[ { "location_id":"23", "scoreSheets":[

我是新来的。在将json数据存储到数据库表中时,我面临一个问题。我试图将json对象存储到表中,但出现错误

以下是我的json数据:

let formData = {"inspection":{
    "date":"23-11-2018",
    "client name" :"John Doe",
    "locations":[
        {
            "location_id":"23",
            "scoreSheets":[
              {
               "name":"EHA",
               "categories":[
                  {
                    "id":"1",
                    "observations":[
                        {
                         "option_id":"56",
                         "option":"lorem ipsum dolor",
                         "marks":"2"
                        }
                    ],
                   "violations":[
                       {
                         "option_id":"59",
                         "option_4":"this is label of option 4",
                         "marks":"-2",
                         "correctiveActions":[
                            {
                              "comment":"lorem ipsum",
                              "image":"errror1.jpg"
                            },
                            {
                              "comment":"dolor set amet",
                              "image":"errror2.jpg"
                            }
                         ]
                       }
                   ],
                   "subscore":"4"
                  }
                ],
              "foodInspections":[
                {
                  "collection_site":"3",
                  "hazardousItems":"4",
                  "non-compliant_food":"lorem ipsum",
                  "potential_cause":"lorem ipsum"
                }
              ],
              "refrigerations":[
                 {
                   "unit_identification":"lskdre",
                   "unit temprature":"34"
                 }
              ],
          "totalScore":"75"
            }
        ]

        }
    ],
    "finalScore":"100"
}}; 
这是我的密码:

db = SQLite.openDatabase(database_name, database_version, database_displayname, database_size, this.openCB, this.errorCB);
 db.transaction((tx) => {
    tx.executeSql('CREATE TABLE IF NOT EXISTS Inspections( '
     + 'id INTEGER PRIMARY KEY NOT NULL, '
     + 'inspector_id INTEGER NOT NULL, '
     + 'inspection_data TEXT ); ', [], this.successCB, this.errorCB);

     tx.executeSql('INSERT INTO Inspections (inspector_id, inspection_data) VALUES ('+decoded.uid+','+formData+');', []);

});
我想在检查表中插入json数据。我还使用了json.strigify()函数,但没有得到任何解决方案。

尝试以下方法:

 db = SQLite.openDatabase(database_name, database_version, database_displayname, database_size, this.openCB, this.errorCB);
 db.transaction((tx) => {
    tx.executeSql('CREATE TABLE IF NOT EXISTS Inspections( '
     + 'id INTEGER PRIMARY KEY NOT NULL, '
     + 'inspector_id INTEGER NOT NULL, '
     + 'inspection_data TEXT ); ', [], this.successCB, this.errorCB);

     tx.executeSql('INSERT INTO Inspections (inspector_id, inspection_data) VALUES (?,?);', [decoded.uid,formData]);
});