Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
保存读取Unity3d c#谷歌Firebase服务器值。时间戳_Unity3d_Firebase_Firebase Realtime Database - Fatal编程技术网

保存读取Unity3d c#谷歌Firebase服务器值。时间戳

保存读取Unity3d c#谷歌Firebase服务器值。时间戳,unity3d,firebase,firebase-realtime-database,Unity3d,Firebase,Firebase Realtime Database,我想将Server.Timestamp保存到我的Firebase数据库unity3d c#中。我试过几种方法,但都没有结果。从GoogleFirebase示例中,我可以看到时间戳被保存为一个长文件 但他们的示例中没有一个真正涉及保存或读取此值 "chats": { "one": { "title": "Historical Tech Pioneers", "lastMessage": "ghopper: Relay malfunction found. Cause

我想将Server.Timestamp保存到我的Firebase数据库unity3d c#中。我试过几种方法,但都没有结果。从GoogleFirebase示例中,我可以看到时间戳被保存为一个长文件 但他们的示例中没有一个真正涉及保存或读取此值

"chats": {
    "one": {
      "title": "Historical Tech Pioneers",
      "lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
      "timestamp": 1459361875666
    },
    "two": { ... },
    "three": { ... }
  },
我找不到一个简单的示例来保存和读取servervalue.timestamp。 基本上,我想知道如何在c#中保存和使用Google Firebase ServerValue.Timestamp


谢谢。

在unity应用程序中,您可以创建要发送的JSON,并将时间戳值替换为以下内容:

"chats": {
    "one": {
      "title": "Historical Tech Pioneers",
      "lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
      "timestamp": {".sv" : "timestamp"}
    },
    "two": { ... },
    "three": { ... }
    },
然后服务器将替换

{".sv" : "timestamp"}

您将能够将“timestamp”字段作为一个长字符串来读取

下面是一个工作示例:

        Dictionary<string, object> scoreUpdate = new Dictionary<string, object> ();
        Dictionary<string, object> timestamp = new Dictionary<string, object> ();
        timestamp [".sv"] = "timestamp";
        scoreUpdate ["scores/" + userID + "/name"] = name;
        scoreUpdate ["scores/" + userID + "/score"] = -score;
        scoreUpdate ["scores/" + userID + "/time/"] = timestamp;

        DBRef.Root ().UpdateChildrenAsync (scoreUpdate);
Dictionary scoreUpdate=new Dictionary();
字典时间戳=新字典();
时间戳[“.sv”]=“时间戳”;
scoreUpdate[“scores/”+userID+“/name”]=name;
scoreUpdate[“分数/”+userID+“/score”]=-分数;
scoreUpdate[“scores/”+userID+“/time/”]=时间戳;
Root().UpdateChildrenAsync(scoreUpdate);

谢谢。你能给出一个非常简单的例子,我们可以用c#来做这件事吗。我尝试了好几种方法,但都没能长期保存下来。
        Dictionary<string, object> scoreUpdate = new Dictionary<string, object> ();
        Dictionary<string, object> timestamp = new Dictionary<string, object> ();
        timestamp [".sv"] = "timestamp";
        scoreUpdate ["scores/" + userID + "/name"] = name;
        scoreUpdate ["scores/" + userID + "/score"] = -score;
        scoreUpdate ["scores/" + userID + "/time/"] = timestamp;

        DBRef.Root ().UpdateChildrenAsync (scoreUpdate);