Jump to content

Recommended Posts

Posted

I have a JSON file with a bunch of objects in it with values that I need to read. How would I go about being able to read this file and access the values. I understand that I need to use GSON but here are my issues.
1. How do I register the file pathway because it does now like using the qualified name. Also is my JSON Reader created correctly?
 

public class GSONDamageResistanceReader 
{
	public static void Init()
	{
		String file = "/DungeonCraft/src/main/resources/data/dungeoncraft/tags/items/armor_damage_type_resistance_values.json"; //bad file path
		Gson gson = new GsonBuilder().create();
				
		try (Reader reader = new FileReader(file))
		{
			ArmorResistance armor = gson.fromJson(reader, ArmorResistance.class);
			
			System.out.println(armor);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
}

 

2. this is a sample of my JSON file to read and the values I need to get are the resistances. Would I need to store these objects in an array and then use my ArmorResistance class to set and get the values?

{
	"minecraft:leather_chestplate": 
	{
		"slashing_resistance" : 1,
		"piercing_resistance" : 1,
		"bludgeoning_resistance" : 1
	},

	"minecraft:leather_leggings": 
	{
		"slashing_resistance" : 1,
		"piercing_resistance" : 1,
		"bludgeoning_resistance" : 1
	}
}

 

Thanks in advance for the help. If you need anymore information let me know, been stuck on this for a while and cant find much else to help.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.