我正在尝试将对象放入sqlite表中。我正在为此使用react-native-sqlite。当我通过将其转换为字符串来存储对象时,它存储为[object,object]
let water_characterstics = {"summer": {"bod": CSbodSummer,"cod": CScodSummer,"tss":CStssSummer,"mcoli":CSmcoliSummer},
"winter": {"bod": CSbodWinter,"cod": CScodWinter,"tss":CStssWinter,"mcoli":CSmcoliWinter},
"current": {"bod": CSbodCurrent,"cod": CScodCurrent,"tss":CStssCurrent,"mcoli":CSmcoliCurrent}
}
let wCC = water_characterstics.toString();
db.transaction(function(tx) {
tx.executeSql(
'INSERT INTO stream_liquid_untapped (city_id, drain_name,drain_type,survey_type, drain_status, pollution_reason,status_latitude,status_longitude, treatment_type, stream_flow, meeting_latitude, meeting_longitude, meeting_avatar1_source, meeting_avatar2_source, meeting_avatar1_name, meeting_avatar2_name, characterstic_water, remarks, synced) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
[1, drain_name,drain_type_number,1,3,pA,0,0,tapValue,stream_flow,ganga_meet_latitude,ganga_meet_longitude,av1_meeting_source,av2_meeting_source,av1_meeting_name,av2_meeting_name,wCC,rmrks,false],
(tx, results) => {
console.log('Results', results.rowsAffected);
if (results.rowsAffected > 0) {
that.setState({ShowSaveModal:true});
} else {
Alert.alert(
'Failed',
[
{
text: 'Ok',
},
],
{ cancelable: false }
);
}
}
);
});
答案 0 :(得分:2)
您执行了water_characterstics.toString()
,该操作始终返回[object Object]
。相反,您应该进行JSON.stringify(water_characterstics)
。
请参见https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify