Java 如何从嵌套的json volley/android检索数据

Java 如何从嵌套的json volley/android检索数据,java,android,json,android-volley,jsonparser,Java,Android,Json,Android Volley,Jsonparser,我想从这个JSON中获取所有标题。我正在使用截击库 JSON来源: 我的代码: public void getAllName(){ String urls = "https://sheets.googleapis.com/v4/spreadsheets/1AtYF5g2_A3AiAhejVj595bDLxO1zoGq7PNGjbdV9U8Q?fields=sheets.properties.title&key=AIzaSyDLeY5OUn8KKHeBY6PSZJbBE8

我想从这个JSON中获取所有标题。我正在使用截击库

JSON来源:

我的代码:

public void getAllName(){
    String urls = "https://sheets.googleapis.com/v4/spreadsheets/1AtYF5g2_A3AiAhejVj595bDLxO1zoGq7PNGjbdV9U8Q?fields=sheets.properties.title&key=AIzaSyDLeY5OUn8KKHeBY6PSZJbBE8rIIME_9dc";

    RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, urls,
            null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject feedObj = response.getJSONObject("sheets");
                JSONArray entryArray = feedObj.getJSONArray("properties");

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    queue.add(jsonObjectRequest);
}
public void getAllName(){
字符串URL=”https://sheets.googleapis.com/v4/spreadsheets/1AtYF5g2_A3AiAhejVj595bDLxO1zoGq7PNGjbdV9U8Q?fields=sheets.properties.title&key=AIzaSyDLeY5OUn8KKHeBY6PSZJbBE8rIIME_9dc";
RequestQueue=Volley.newRequestQueue(MainActivity.this);
JsonObjectRequest JsonObjectRequest=新的JsonObjectRequest(Request.Method.GET,URL,
null,新响应。侦听器(){
@凌驾
公共void onResponse(JSONObject响应){
试一试{
JSONObject feedObj=response.getJSONObject(“表单”);
JSONArray entryArray=feedObj.getJSONArray(“属性”);
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
}
});
add(jsonObjectRequest);
}
请告诉我如何得到所有的标题。。。 TIA参考:

从Json响应中,标题数据位于工作表中的属性中。 可以使用getJsonObject(“属性名称”)从Json检索JsonObject

现在,您可以以相同的方式使用properties.title并根据需要使用它


此外,我建议对网络任务进行改装,因为它使网络任务更容易。

您可以执行以下操作:

JSONArray jsonArray = jsonObject.getJSONArray("sheets");

List<String> titles = IntStream.range(0,jsonArray.length())
        .mapToObj(i -> jsonArray.getJSONObject(i)
                .getJSONObject("properties")
                .getString("title"))
        .collect(Collectors.toList());

很好,非常感谢@BuildSlayer我很高兴能帮上忙:)你可以试着解决这个“@BuildSlayer”
JSONArray jsonArray = jsonObject.getJSONArray("sheets");

List<String> titles = IntStream.range(0,jsonArray.length())
        .mapToObj(i -> jsonArray.getJSONObject(i)
                .getJSONObject("properties")
                .getString("title"))
        .collect(Collectors.toList());
[CSE522, EEE, BBA, MBA, SWE555, CSE625, CSE721, CSE250, CSE775, CSE499]