-2

I have a json string that looks as follows

{ "shares": [ { "shareId": "5792c70c470ac0c817000002", "type": "group", "rule": "view", "subscribe": false, "everyone": true } ] }

It is an array of one object. I would like to get the string "5792c70c470ac0c817000002" from it.

I was able to get the JsonObject as follows

String jsonString  = "{ \"shares\": [ { \"shareId\": \"5792c70c470ac0c817000002\", \"type\": \"group\", \"rule\": \"view\", \"subscribe\": false, \"everyone\": true } ] }\"
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(jsonString).getAsJsonObject();

However, I would like to get the member shareId of the first member of this array. How can I do that?

tubby
  • 2,074
  • 3
  • 33
  • 55

1 Answers1

1

Try this :

jsonObject .getJsonArray("shares").getJsonObject(0).getString("shareId");
Seif
  • 86
  • 6