2015-10-05 17 views
1

我得到這個jsonarray解析JSON在Android中使用GET方法與排球工作室

{ 
    "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" 
} 
] 
} 

這是我在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); 

} 

所以,我不能解析此Json Array,我已經做了這個,但是用POST方法,所以我想知道你們中的任何人能否告訴我如何使用凌空

+0

你可以發佈什麼和你在哪裏得到的錯誤/異常? – pgiitu

回答

1
{ 
    "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" 
     } 
    ] 
} 

首先,這是一個JSONObject,而不是JSONArray。你可以去herehere更多信息

的JSONObject:......與開頭的字符串{(左大括號),並與結束}(右括號)。

JSONArray:...與開始[(左括號),並用結束](右括號)的字符串。

其結果是,你可以使用的JsonObjectRequest代替JsonArrayRequest

希望這有助於!

相關問題