소스 검색

C# Correct how to type cast Dictionaries returned from JSONParseResult

Casting with either `(Godot.Collections.Dictionary<string,
object>)parsedResult` or `parsedResult as
Godot.Collections.Dictionary<string, object>` fails with an
InvalidCastException (or silently returning null with the `as` keyword).
Instead, a typed constructor using `new` should be used.
Amanda Steinwedel 5 년 전
부모
커밋
59731584ab
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      tutorials/io/saving_games.rst

+ 1 - 1
tutorials/io/saving_games.rst

@@ -267,7 +267,7 @@ load function:
         while (saveGame.GetPosition() < save_game.GetLen())
         while (saveGame.GetPosition() < save_game.GetLen())
         {
         {
             // Get the saved dictionary from the next line in the save file
             // Get the saved dictionary from the next line in the save file
-            var nodeData = (Godot.Collections.Dictionary<string, object>)JSON.Parse(saveGame.GetLine()).Result;
+            var nodeData = new Godot.Collections.Dictionary<string, object>((Godot.Collections.Dictionary)JSON.Parse(saveGame.GetLine()).Result);
 
 
             // Firstly, we need to create the object and add it to the tree and set its position.
             // Firstly, we need to create the object and add it to the tree and set its position.
             var newObjectScene = (PackedScene)ResourceLoader.Load(nodeData["Filename"].ToString());
             var newObjectScene = (PackedScene)ResourceLoader.Load(nodeData["Filename"].ToString());