-1

以下のコードを実行すると、次のような例外が表示されます

「JSON パーサー﹕ データ org.json.JSONException の解析中にエラーが発生しました: タイプ org.json.JSONObject$1 の値 null を 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"}
4

1 に答える 1

0

コードによると、JsonArray を期待していますが、データ例には配列が含まれていません (間違って配置したと思います)。配列にヌルがないことを確認してください。

于 2016-03-17T16:36:05.943 に答える