1

アプリケーションで使用するためにサーバーからテルグ語で書かれたテキストを取得することは可能ですか?Jsonには以下のフォーマットを使用しました。avdのlogcatでいくつかのシンボルにエラーが発生しています。そうでない場合は、そのような種類のテキストを取得するのに適しています。

{
"contacts": [
    {
            "id": "c200",
            "name": "అశ్విని",
            "email": "అశ్విని@అశ్విని.అశ్విని",
            "address": "అశ్విని",
            "gender" : "అశ్విని",
            "phone": {
                "mobile": "అశ్విని",
                "home": "అశ్విని",
                "office": " రేవతి"
            }
    },
    {
            "id": "c201",
            "name": "అశ్విని ram",
            "email": "అశ్విని@అశ్విని.అశ్విని",
            "address": "అశ్విని",
            "gender" : "అశ్విని",
            "phone": {
                "mobile": "అశ్విని",
                "home": "అశ్విని",
                "office": "అశ్విని"
            }
    }
]
} 

以下は私がデータを取得するために使用したコードです

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}

public JSONObject getJSONFromUrl(String url) {

    // Making HTTP request
    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();           

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

}
}
4

2 に答える 2

1

アセットフォルダでNTR.TTFフォントを使用する必要があり、以下の行を変更する必要があります

BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8000);
于 2012-12-18T12:26:10.077 に答える
0

JSONコンテンツは、デフォルトの文字セットとしてUTF-8を使用します(RFC 4627の第3章を参照)。サーバーが正しいエンコーディングで応答を返すこと、およびストリームリーダーにUTF-8エンコーディングを明示的に使用することを確認する必要があります。

BufferedReader r = new BufferedReader(new InputStreamReader(instream, "UTF-8"), 8000);
于 2012-10-31T12:57:56.383 に答える