Web サイトから json 文字列を取得する次のコードがあります。
post.setEntity(entity);
HttpResponse responsePOST = client.execute(post);  
HttpEntity resEntity = responsePOST.getEntity();
result = EntityUtils.toString(resEntity, HTTP.UTF_8);
これは、結果の json の例です。
{"status":"0","user_id":"123","name":"test","session_code":"6f33d4ee610651530f04b1f700ebc36d"}
これは jsonlint.com で検証されます。を使用して解析しようとします
JSONObject jo = new JSONObject(result);
Android 4 では、コードは正常に動作しますが、以前のバージョンでは、
org.json.JSONException: Value  of type java.lang.String cannot be converted to JSONObject
json文字列をオンラインにする代わりにハードコーディングしたところ、以前のバージョンで機能しました。http リクエストの出力をログに記録したところ、リクエストが成功するたびに変化するセッション コードを除いてすべてが同一であることがわかりましたが、両方のセッション コードの長さと形式は同じでした。
これの理由と修正方法を知っている人はいますか?
アップデート:
if (!email.isEmpty() && !password.isEmpty()){
    try {
        HttpClient client = new DefaultHttpClient();  
        String postURL = "http://www.xxxxxx.com/api/login.php";
        HttpPost post = new HttpPost(postURL);
        List<NameValuePair> postParams = new ArrayList<NameValuePair>();
        postParams.add(new BasicNameValuePair("email", email));
        postParams.add(new BasicNameValuePair("pass", password));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams, HTTP.UTF_8);
        post.setEntity(entity);
        HttpResponse responsePOST = client.execute(post);  
        HttpEntity resEntity = responsePOST.getEntity();
        result = EntityUtils.toString(resEntity, HTTP.UTF_8);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.toString());
    } catch (ClientProtocolException e) {
        Log.e(TAG, e.toString());
    } catch (ParseException e) {
        Log.e(TAG, e.toString());
    } catch (IOException e) {
        Log.e(TAG, e.toString());
    }
}
if (result != null) {
    try {
        JSONObject jo = new JSONObject(result);
        switch (jo.getInt("status")) {
            case 0 : {
                userName = jo.getString("name");
                userID = jo.getInt("user_id");
                authCode = jo.getString("session_code");
                return 0;
            }
            default:
                return jo.getInt("status");
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
    }
}