如何从Java中的JSON获取一个对象数组(Object [])

时间:2022-09-25 10:15:23

I have the following array of Objects put in a JSONObject:

我在JSONObject中放置了以下对象数组:

Object[] objs=new Object[4];
objs[0]=null;
objs[1]=1234;
objs[2]="test1";
objs[3]="test2";

JSONObject j=new JSONObject();
j.put("objs", objs);

Later in the code, I will need to get this array from the JSONObject and use it.

稍后在代码中,我将需要从JSONObject获取此数组并使用它。

I've tried several ways so far to get "objs" from the JSON and assign it to an Array of Objects with no luck.

到目前为止,我已经尝试了几种方法从JSON中获取“objs”并将其分配给没有运气的对象数组。

Does anyone has any idea how I can do this?

有谁知道我怎么能这样做?

1 个解决方案

#1


1  

Just:

Object[] objsAgain = (Object[]) j.get("objs");

#1


1  

Just:

Object[] objsAgain = (Object[]) j.get("objs");