简体   繁体   English

Firebase 数据库错误:System.Collections.Generic.Dictionary`2[System.String,System.Object]

[英]Firebase Database Error: System.Collections.Generic.Dictionary`2[System.String,System.Object]

Firebase Databse Fails to download data when needed in between other similar operations in app. Firebase 数据库在应用程序中的其他类似操作之间需要时下载数据失败。

System.Collections.Generic.Dictionary`2[System.String,System.Object] System.Collections.Generic.Dictionary`2[System.String,System.Object]

Firebase Cannot take do new GetValueASync sometimes in middle of similar operations of app and throws System.Collections.Generic.Dictionary 2[System.String,System.Object]` as a snapshot value. Firebase 在应用程序的类似操作中有时无法执行新的GetValueASync并抛出System.Collections.Generic.Dictionary 2[System.String,System.Object]` 作为快照值。

Steps to reproduce: Setup any unity project with realtime databse perform non stop multiple times: .GetValueAsync().ContinueWithOnMainThread(task => then you will get value as System.Collections.Generic.Dictionary 2[System.String,System.Object]` instead of any child/key/database value.重现步骤:使用实时数据库设置任何统一项目多次不间断执行: .GetValueAsync().ContinueWithOnMainThread(task =>然后您将获得System.Collections.Generic.Dictionary 2[System.String,System.Object] 的值` 而不是任何子/键/数据库值。

public void aaaa() {
    Reference.Child("Users").OrderByChild("About/XP").StartAt(1).LimitToFirst(12).GetValueAsync().ContinueWithOnMainThread(task => {
      if (task.IsFaulted) {

        return;
      } else if (task.IsCompleted) {
        DataSnapshot Snapshot = task.Result;
        if (Snapshot != null)
          Debug.Log(Snapshot.Value);
        return;
      }
      return;

    });

Well this happens if you use ToString (which is what Debug.Log does internally) on a dictionary or in general any object of a type that doesn't implement it explicitly, it simply returns the same as GetType().FullName .好吧,如果您在字典上使用ToString (这是Debug.Log在内部执行的操作),或者通常任何未显式实现它的类型的 object ,就会发生这种情况,它只返回与GetType().FullName相同的内容。

Default implementations of the Object.ToString method return the fully qualified name of the object's type. Object.ToString 方法的默认实现返回对象类型的完全限定名称。

So it looks like the type is a Dictionary<string, object> .所以看起来类型是Dictionary<string, object>

If you want to see all items you rather want to do eg如果您想查看所有您想做的项目,例如

foreach(var kvp in Snapshot.Value)
{
    Debug.Log($"Key: {kvp.Key}, Value: {kvp.Value}");
}

Note though: while the key is a string , the value once again might be a type not implementing ToString in which case again it will simply print out the type name.但请注意:虽然 key 是string ,但 value 可能再次是未实现ToString的类型,在这种情况下,它将再次简单地打印出类型名称。


If you really want to print out the entire structure (as far as the values are serializable) you could use Newtonsoft JSON.Net and convert the entire dictionary into a human readable JSON format.如果您真的想打印出整个结构(只要值是可序列化的),您可以使用Newtonsoft JSON.Net并将整个字典转换为人类可读的 JSON 格式。

See Serialize a Dictionary请参阅序列化字典

string json = JsonConvert.SerializeObject(Snapshot.Value, Formatting.Indented);
Debug.Log(json);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' - Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' 从System.Collections.Generic.Dictionary`2 [System.Object,System.Object]中读取数据 - Read Data From System.Collections.Generic.Dictionary`2[System.Object,System.Object] 无法将System.String强制转换为System.Collections.Generic.Dictionary类型 <string, string> 与会话变量 - Unable to cast System.String to type System.Collections.Generic.Dictionary<string, string> with Session variable 无法将类型字符串隐式转换为System.Collections.Generic.Dictionary <string,System.Collections.Generic.Dictionary><string,object> &gt; - Cannot implicitly convert type string to System.Collections.Generic.Dictionary<string,System.Collections.Generic.Dictionary><string,object>> LINQ to Entities 无法识别方法“System.Collections.Generic.Dictionary”2[System.Int32,System.String] ToDictionary - LINQ to Entities does not recognize the method 'System.Collections.Generic.Dictionary`2[System.Int32,System.String] ToDictionary 枚举System.Collections.Generic.Dictionary中的键<string,string> - enumerate keys in in a System.Collections.Generic.Dictionary<string,string> System.Collections.Generic.Dictionary =终极表现? - System.Collections.Generic.Dictionary = Ultimate performance? System.Collections.Generic.Dictionary foreach顺序 - System.Collections.Generic.Dictionary foreach order 将System.Collections.Generic.Dictionary转换为XDocument - Turn a System.Collections.Generic.Dictionary into an XDocument 反序列化 System.Collections.Generic.Dictionary - deserializing System.Collections.Generic.Dictionary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM