I'm trying to parse a JSON file with GSON with the following structure:
{
"state": 0,
"orders": {
"1": {
"idOrder": "1564",
"price": "7.99",
},
"3": {
"idOrder": "4896",
"price": "9.99",
},
"7": {
"idOrder": "4896",
"price": "10.99",
}
}
}
I made the classes as same structure (with setters and getters)
public class myJson {
private int error;
private Orders orders; }
public class Orders {
@SerializedName("1")
private _1 _1;}
public class _1 {
private String idOrder;
private String price;}
and in main I am using like this:
Gson gson = new Gson();
BufferedReader br = new BufferedReader (new FileReader("base.json"));
Json jsonOffline = gson.fromJson(br, myJson.class);
System.out.println("1 - Orderid: " + jsonOffline.getOrders().get1().getidOrder() );
*
And it works perfectly printing: "1 - Orderid: 1564"
*
And now my problem is that these numbers (1,3,7) in the JSON file are random and there may be many orders. Is there any way for me to indicate a range of numbers, for example, 1-1000, and in that case if the result is not null to do the same?
I mean, to avoid having to create 1000 classes like class _1