在Android中Studio中使用GET方法,排球JSON解析 [英] Parsing JSON using GET method with Volley in Android Studio

查看:226
本文介绍了在Android中Studio中使用GET方法,排球JSON解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了这个 JSON 阵列

  {
   会议:[
   {
    标识:1,
    名:Conferencia独断
    说明:Conferencia边chingona LALALA,
    扬声器:豪尔赫
    传:BIOO
    地方:{
     名:演艺厅,
     说明:presentacion德peliculasÿdocumentales
   },
   日期:31/10/2015,
   时间:16:00
}
]
}

这是在我的code Android的工作室

 队列= Volley.newRequestQueue(本);    JsonArrayRequest JsonRequest =新JsonArrayRequest(Request.Method.GET,网址,新Response.Listener< JSONArray>(){
        @覆盖
        公共无效onResponse(JSONArray响应){            尝试{                的for(int i = 1,计数= response.length(); I<计数;我++){                    EventInfo eventInfo =新EventInfo();
                    eventInfo.name = response.getJSONObject(I).getString(名称);
                    eventInfo.date = response.getJSONObject(I).getString(DATE);
                    eventInfo.hour_event = response.getJSONObject(I).getString(时代);
                    eventInfo.link =htt​​p://www.tallertoa.com/v1/files/gimgs/7_botanico-lamina-21.jpg;
                    eventInfo.description = response.getJSONObject(I).getString(说明);
                    eventInfos.add(eventInfo);
                }
                  recList.setAdapter(适配器);
                Log.e(JSON,response.toString());            }赶上(JSONException E){
                showErrorDialog(错误JSON解析器,错误人parsear objeto的Json Evento);
                Log.e(JSON错误,e.toString());
            }        }    },新Response.ErrorListener(){
        @覆盖
        公共无效onErrorResponse(VolleyError错误){        }
    });
    queue.add(JsonRequest);}

所以,我不能解析此JSON数组,我已经做到了这一点,但与POST方法,所以我想知道如果任何你能告诉我怎么做到这一点使用凌空


解决方案

  {
    会议:[
        {
            标识:1,
            名:Conferencia独断
            说明:Conferencia边chingona LALALA,
            扬声器:豪尔赫
            传:BIOO
            地方:{
                名:演艺厅,
                说明:presentacion德peliculasÿdocumentales
            },
            日期:31/10/2015,
            时间:16:00
        }
    ]
}

首先,这是一个JSONObject,而不是一个JSONArray。你可以去 rel=\"nofollow\">和的这里更多信息


  

JSONObject的:......是开始{(左括号)和结束} (右括号)的字符串。


  
  

JSONArray:...以开始[(左括号)和结束] (右括号)的字符串。


因此​​,你可以使用 JsonObjectRequest 而不是 JsonArrayRequest

希望这有助于!

I got this json array:

  {
   "conferences": [
   {
    "id": 1,
    "name": "Conferencia Magistral",
    "description": "Conferencia bien chingona lalala",
    "speaker": "Jorge",
    "biography": "bioo",
    "place": {
     "name": "Auditorio",
     "description": "Presentacion de peliculas y documentales"
   },
   "date": "31/10/2015",
   "time": "16:00"
}
]
}

And this is my code in Android Studio:

 queue = Volley.newRequestQueue(this);

    JsonArrayRequest JsonRequest = new JsonArrayRequest(Request.Method.GET, url, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {

            try {

                for (int i = 1, count = response.length(); i < count; i++) {

                    EventInfo eventInfo = new EventInfo();
                    eventInfo.name = response.getJSONObject(i).getString("name");
                    eventInfo.date =   response.getJSONObject(i).getString("date");
                    eventInfo.hour_event =   response.getJSONObject(i).getString("time");
                    eventInfo.link="http://www.tallertoa.com/v1/files/gimgs/7_botanico-lamina-21.jpg";
                    eventInfo.description = response.getJSONObject(i).getString("description");
                    eventInfos.add(eventInfo);


                }
                  recList.setAdapter(adapter);
                Log.e("JSON", response.toString());

            } catch (JSONException e) {
                showErrorDialog("error Json parser", "error al parsear objeto Json Evento");
                Log.e("json error",e.toString());
            }

        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });
    queue.add(JsonRequest);

}

So, i cant parse this Json Array, I've done this but with POST method, so i was wondering if any of you could tell me how to do this using volley

解决方案

{
    "conferences": [
        {
            "id": 1,
            "name": "Conferencia Magistral",
            "description": "Conferencia bien chingona lalala",
            "speaker": "Jorge",
            "biography": "bioo",
            "place": {
                "name": "Auditorio",
                "description": "Presentacion de peliculas y documentales"
            },
            "date": "31/10/2015",
            "time": "16:00"
        }
    ]
}

Firstly, this is a JSONObject, not a JSONArray. You can go here and here for more information

JSONObject: ...A string beginning with { (left brace) and ending with } (right brace).

JSONArray: ...A string that begins with [ (left bracket) and ends with ] (right bracket).

As a result, you can use a JsonObjectRequest instead of JsonArrayRequest

Hope this helps!

这篇关于在Android中Studio中使用GET方法,排球JSON解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆