-3

I have this JSON file :

{
    "player1" : [
        "kills" : 0,
        "deaths" : 0,
        "wins" : 0
    ],
    "player2" : [
        "kills" : 0,
        "deaths" : 0,
        "wins" : 0
    ]
}

But i don't no how use it. I do not know how to call the file, I tried with a parser but I did not succeed. I would like to use that in a Java program.

Can someone help me and at the same time explain to me?

Taupeman
  • 47
  • 1
  • 8

2 Answers2

0
  1. Read the whole file and save it to string

  2. Now create the JSONObject using that string

    JSONObject x = new JSONObject(string);

Ragesh
  • 205
  • 3
  • 11
0

You can use Jackson lib to convert your Json file to Java Object.

Lets Assume your file is Player.json

ObjectMapper mapper = new ObjectMapper(); InputStream is = Player.class.getResourceAsStream("/Player.json"); playerObj = mapper.readValue(is, Player.class);

Varun
  • 196
  • 1
  • 20