-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"}
請使用您編寫代碼的語言對其進行標記,幷包含您要解析的JSON,因爲它可能是輸入問題而不是代碼。 – Waxen