Godot Version
Godot 4.3 .NET
Question
I want to parse a JSON string to a Dictionary. For some reason I get a “CS0103: The name ‘JSON’ does not exist in the current context”
This is my code:
using Godot;
using System;
using Godot.Collections;
public partial class Inventory : CanvasLayer
{
private const string itemsFilePath = "res://Scripts/items.json";
private GridContainer gridContainer;
private Dictionary<Item, int> loadItemsFromJson(){
string json = System.IO.File.ReadAllText(itemsFilePath);
Dictionary jsonDict = JSON.Parse(json).Result as Dictionary;
Dictionary<Item, int> items = new Dictionary<Item, int>();
foreach (Dictionary itemDict in jsonDict["items"]){
Item item = new Item(itemDict);
items.Add(item, Convert.ToInt32(itemDict["quantity"]));
}
return items;
}
private void createItemBoxes(Dictionary<Item, int> items){
foreach (KeyValuePair<Item, int> item in items){
ItemBox itemBox = new ItemBox(item.Key, item.Value);
gridContainer.AddChild(itemBox);
}
}
public override void _Ready()
{
gridContainer = GetNode<GridContainer>("GridContainer");
createItemBoxes(loadItemsFromJson());
}
}
Is there a way to fix my JSON.Parse or should I use some other solution?