首页 文章

将JSON加载到Firestore中 - 数据类型

提问于
浏览
1

Native JSON仅支持string,number,boolean . Firestore支持其他类型 - 时间戳,地理位置,日期/时间 . 如何格式化JSON以加载这些数据类型?

1 回答

  • 1

    以下是有关支持的数据类型的一些信息: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
        },
        // Blobs are base64 encoded strings
        blobExample: "RmlyZXN0b3JlIGlzIGF3ZXNvbWUh"
    };
    

    有关protobuf到JSON的更多信息,请访问:https://developers.google.com/protocol-buffers/docs/proto3#json

相关问题