How to cast JSONArray to int array?

后端 未结 5 1546
一生所求
一生所求 2020-12-06 18:31

I\'m having problems with the method JSONObject sayJSONHello().

@Path(\"/hello\")
public class SimplyHello {

    @GET
    @Produces(MediaType.A         


        
5条回答
  •  庸人自扰
    2020-12-06 19:01

    If you can accept a List as a result, and also can accept using Gson, there is a pretty easy way of doing this, in just a few lines of code:

    Type listType = new TypeToken>() {}.getType();
    List numbers = new Gson().fromJson(jobj.get("numbers"), listType);
    

    I realize this is not exactly what you are asking for, but in my experience, a list of integers can be used in many of the same ways as a basic int[]. Further info on how to convert a linkedlist to an array, can be found here: How to convert linkedlist to array using `toArray()`?

提交回复
热议问题