将 JSON 加载到 Firestore - 数据类型
Load JSON into Firestore - data types
原生JSON只支持字符串、数字、布尔值。 Firestore 支持其他类型 - 时间戳、地理点、date/time。您应该如何格式化 JSON 以加载这些数据类型?
以下是有关支持的数据类型的一些信息:https://firebase.google.com/docs/firestore/manage-data/data-types
还有一个例子:
var docData = {
stringExample: "Hello world!",
booleanExample: true,
// Note that numbers can be either integers or floating point
numberExample: 3.14159265,
// JSON representation as RFC 3339 String with timezone Z
// e.g. 1815-12-10T00:00:00.000Z
dateExample: new Date("December 10, 1815"),
arrayExample: [5, true, "hello"],
nullExample: null,
objectExample: {
a: 5,
b: {
nested: "foo"
}
},
// JSON object w/ latitude and longitude keys
geoPointExample: {
latitude: 37.773972
longitude: -122.431297
},
// FIRESTORE GEOPOINT
geoPointExample2: new firebase.firestore.GeoPoint(37.7739,-122.4312)
// Blobs are base64 encoded strings
blobExample: "RmlyZXN0b3JlIGlzIGF3ZXNvbWUh"
};
有关 JSON 的 protobuf 的更多信息可在此处获得:https://developers.google.com/protocol-buffers/docs/proto3#json
原生JSON只支持字符串、数字、布尔值。 Firestore 支持其他类型 - 时间戳、地理点、date/time。您应该如何格式化 JSON 以加载这些数据类型?
以下是有关支持的数据类型的一些信息:https://firebase.google.com/docs/firestore/manage-data/data-types
还有一个例子:
var docData = {
stringExample: "Hello world!",
booleanExample: true,
// Note that numbers can be either integers or floating point
numberExample: 3.14159265,
// JSON representation as RFC 3339 String with timezone Z
// e.g. 1815-12-10T00:00:00.000Z
dateExample: new Date("December 10, 1815"),
arrayExample: [5, true, "hello"],
nullExample: null,
objectExample: {
a: 5,
b: {
nested: "foo"
}
},
// JSON object w/ latitude and longitude keys
geoPointExample: {
latitude: 37.773972
longitude: -122.431297
},
// FIRESTORE GEOPOINT
geoPointExample2: new firebase.firestore.GeoPoint(37.7739,-122.4312)
// Blobs are base64 encoded strings
blobExample: "RmlyZXN0b3JlIGlzIGF3ZXNvbWUh"
};
有关 JSON 的 protobuf 的更多信息可在此处获得:https://developers.google.com/protocol-buffers/docs/proto3#json