【发布时间】:2021-05-05 02:41:13
【问题描述】:
我对 c# 很陌生,我正在尝试将从 firestore 获得的数据保存到一个字符串中,我已经搜索并尝试了许多不同的东西,但似乎无法得到它,非常感谢任何帮助,这是我的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase;
using Firebase.Database;
using Firebase.Firestore;
using Firebase.Extensions;
using System;
public class FirestoreGet : MonoBehaviour
{
public string Name;
public string lastName;
// Start is called before the first frame update
void Start()
{
Debug.Log("Start");
call();
}
async void call()
{
FirebaseFirestore db = FirebaseFirestore.DefaultInstance;
DocumentReference docRef = db.Collection("Test").Document("Test");
DocumentSnapshot snapshot = await docRef.GetSnapshotAsync();
if (snapshot.Exists)
{
Debug.LogFormat("Document data for {0} document:", snapshot.Id);
Dictionary<string, object> data = snapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in data)
{
Debug.LogFormat("{0}: {1}", pair.Key, pair.Value);
}
}
else
{
Debug.LogFormat("Document {0} does not exist!", snapshot.Id);
}
}
}
【问题讨论】:
-
你能分享你拥有的任何调试日志吗(为了方便,这应该可以在编辑器中运行)?确认一下,您的“文档”是否命名为
Test,它是否也在名为Test的“集合”中?如果 Firestore 控制台的屏幕截图不显示太多信息,它也会有所帮助。你是否也在做类似var dependencyStatus = await FirebaseApp.CheckAndFixDependenciesAsync()的事情并等待它在这个脚本之外返回? -
是的,我的调试控制台返回数据,我只是不确定如何将它返回的数据转换成字符串
标签: c# firebase unity3d google-cloud-firestore