0

文字列を渡して JSONObject を作成すると、エラーが発生します。

Org.json.JSONException: Unterminated string at character

私のJSON文字列は次のとおりです。

{"Count":741,"Data":[{rec1....},{rec2...}, etc]}

これは、私が Windows で開発したため、Linux でのみ発生するようで、問題なく動作しました。また、問題は文字列が長すぎることに起因しているようです。アレイを半分以上カットしたところ、問題は解消されました。

この問題を解決するにはどうすればよいですか、または回避策がある場合はどうすればよいですか?

4

2 に答える 2

2

Android studio で AsyncTask を使用している場合は、mysql の HttpURLConnectionin またはデータベースの他の Gestor を参照してください。「String downloadUrl(String myurl)」というメソッドがあり、「int len = 500;」という変数があります。inputStream の読み取りデータの場合、この変数を、読み取る必要のある数値文字に変更します。

 private String downloadUrl(String myurl) throws IOException {
    Log.i("URL",""+myurl);
    myurl = myurl.replace(" ","%20");
    InputStream is = null;
    // Only display the first 500 characters of the retrieved
    // web page content.
    <b>int len = 1500; </b>

    try {
        URL url = new URL(myurl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10000 /* milliseconds */);
        conn.setConnectTimeout(15000 /* milliseconds */);
        conn.setRequestMethod("GET");
        conn.setDoInput(true);
        // Starts the query
        conn.connect();
        int response = conn.getResponseCode();
        Log.d("respuesta", "The response is: " + response);
        is = conn.getInputStream();

        // Convert the InputStream into a string
        String contentAsString = readIt(is, len);
        return contentAsString;

        // Makes sure that the InputStream is closed after the app is
        // finished using it.
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
于 2016-09-20T15:35:23.633 に答える