Godot Engine 3.2 Alpha2
Dictionary
是Godot的内置类型之一
true
inthash ( )生成哈希值Arraykeys ( )键数组intsize ( )大小Arrayvalues ( )值数组
定义
var d = {4: 5, "A key": "A value", 28: [1, 2, 3]}
d["Hi!"] = 0
d = {
22: "value",
"some_key": 2,
"other_key": [2, 3, 4],
"more_key": "Hello"
}
访问值
var d = {} # Create an empty Dictionary.
d.waiting = 14 # Add String "waiting" as a key and assign the value 14 to it.
d[4] = "hello" # Add integer 4 as a key and assign the String "hello" as its value.
d["Godot"] = 3.01 # Add String "Godot" as a key and assign the value 3.01 to it.
Dictionary和JSON的互相转换
Dictionary转换为JSON
var json_str = JSON.print(dict)
JSON转换为Dictionary
var res = JSON.parse(json_str)
var dict = res.result