Jump to content

Json Datei laden und ausgeben


Matzuake
 Share

Recommended Posts

{
  "holz": [
    {
      "itemname": "Eichenholz",
      "item": {
        "material": "OAK_LOG",
        "anzahl": "1"
      },
      "lore": [
        {
          "preis": "10"
        }
      ]
    },
    {
      "itemname": "Brauner Pilzblock",
      "item": {
        "material": "BROWN_MUSHROOM_BLOCK",
        "anzahl": "1"
      },
      "lore": [
        {
          "preis": "15"
        }
      ]
    },
    {
      "itemname": "Tropenbaumlaub",
      "item": {
        "material": "JUNGLE_LEAVES",
        "anzahl": "1"
      },
      "lore": [
        {
          "preis": "2"
        }
      ]
    },
    {
      "itemname": "Eichenholz",
      "item": {
        "material": "OAK_LOG",
        "anzahl": "64"
      },
      "lore": [
        {
          "preis": "64"
        }
      ]
    },
    {
      "itemname": "Eichenholz",
      "item": {
        "material": "OAK_LOG",
        "anzahl": "64"
      },
      "lore": [
        {
          "preis": "10"
        }
      ]
    },
    {
      "itemname": "Brauner Pilzblock",
      "item": {
        "material": "BROWN_MUSHROOM_BLOCK",
        "anzahl": "64"
      },
      "lore": [
        {
          "preis": "960"
        }
      ]
    },
    {
      "itemname": "Tropenbaumlaub",
      "item": {
        "material": "JUNGLE_LEAVES",
        "anzahl": "64"
      },
      "lore": [
        {
          "preis": "128"
        }
      ]
    }
  ]
}

ich würde gerne diese json datei in mein Plugin laden , nur die umsetzung ist etwas naja

ich arbeite noch nicht solange mit Json

Gson gson = new Gson();
ShopItems[] shopItems= gson.fromJson(json, ShopItems[].class);
for(ShopItems shopItem: shopItems)
    System.out.println(shopItem.toString());

ich habe das so probiert aber ohne erfolg

es kommt immer eine java.lang.NullPointerException

Link to comment
Share on other sites

Soll sich die Datei direkt im Plugin befinden oder soll sie aus dem Plugins-Ordner geladen werden?

Was genau soll erst mal ausgegeben werden? Die ganze Datei als String oder bestimmte Objekte der Datei?

Link to comment
Share on other sites

Habe mal ein paar Sachen probiert - bei mir will es auch nicht klappen 😕

Es gibt ja Plugins, die auch Daten von einer Json abgreifen - evtl. findet man bei Github ein paar Beispiele bez. Umsetzung.

Wegen dem parsen der Datei könnte evtl. das hier nützlich sein: https://gist.github.com/DevSrSouza/aa2f39fb2299dfe72b49b52fa46d9a73

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...
B