2016-03-14 119 views
-1

当我执行下面给出的码型的值null,它显示我喜欢

异常“JSON解析器:错误的数据进行解析org.json.JSONException:值null 型org.json.JSONObject $ 1不能被转换为JSONObject的”

这里任何人能帮助我吗?

public class JSONParser { 

static JSONArray jarray = new JSONArray(); 
static JSONObject jobj = new JSONObject(); 


public JSONArray getJSONFromUrl(String url) { 
    StringBuilder builder = new StringBuilder(); 
    HttpClient client = new DefaultHttpClient(); 
    HttpGet httpGet = new HttpGet(url); 
    try { 
     HttpResponse response = client.execute(httpGet); 
     StatusLine statusLine = response.getStatusLine(); 
     int statusCode = statusLine.getStatusCode(); 
     if (statusCode == 200) { 
      HttpEntity entity = response.getEntity(); 
      InputStream content = entity.getContent(); 
      BufferedReader reader = new BufferedReader(new InputStreamReader(content)); 
      String line; 
      while ((line = reader.readLine()) != null) { 
       builder.append(line); 
      } 



     } else { 
      Log.e("==>", "Failed to download file"); 

     } 
    } catch (ClientProtocolException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    // Parse String to JSON object 
    try { 

     jobj = new JSONObject(String.valueOf(builder)); 
     jarray = new JSONArray(jobj); 
    } catch (JSONException e) { 
     Log.e("JSON Parser", "Error parsing data " + e.toString()); 
    } 
    // return JSON Object 
    return jarray; 

} 

}

和米服务器试图得到的数据是

{"eventid":"1","name":"Hacking","text":"6th-7th feb.Faculty i3India  tech","date":"6th-7th","time":"9","venue":"MMH","contact":"9033637371","fee":"800"} 
+1

请使用您编写代码的语言对其进行标记,并包含您要解析的JSON,因为它可能是输入问题而不是代码。 – Waxen

回答

0

根据你的代码,你期待JsonArray,但您的数据例如不包含任何阵列(我认为你把它不正确)。检查数组中是否有空值。

相关问题