2016-12-06 114 views
1

我有一个JavaScript对象为:如何将JavaScript对象插入到sqlite数据库中?

service location : Object 
    formatted_address:"Jharkhand, India" 
    latitude : "23.6101808" 
    longitude :"85.2799354" 

如何我在SQLite数据库插入此in a single column为对象。

当我在我的数据库上执行SELECT查询时,我希望将此列值作为响应中的对象。

回答

2

您可以将其转换为JSON字符串并发送。

JSON.stringify({ 
    service_location: { 
    formatted_address: "Jharkhand, India", 
    latitude: "23.6101808", 
    longitude: "85.2799354" 
    } 
}); 

这将被转换成:

{"service_location":{"formatted_address":"Jharkhand, India","latitude":"23.6101808","longitude":"85.2799354"}} 

这可以使用安全解码:

JSON.parse('{"service_location":{"formatted_address":"Jharkhand, India","latitude":"23.6101808","longitude":"85.2799354"}}'); 
+0

是的,可是当我将在此列执行select查询,我会收到一个字符串但我想收到一个对象。 – lakshay

+1

@lakshay您应该使用PHP中的'json_decode()'或JavaScript中的'JSON.parse()'将其转换为对象。因为在处理数据库中的数据时,您不能存储字符串以外的任何内容。 –