使用JSON泰卢固文 [英] telugu text using json

查看:142
本文介绍了使用JSON泰卢固文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从服务器检索的应用中使用写在泰卢固语的文字。我已经使用的Json以下格式。这是给我的错误在某些符号在AVD的logcat的。如果没有这将是适用于获得这种类型的文本。

  {
人脉:[
    {
            ID:C200,
            名:అశ్విని
            电子邮件:అశ్విని@అశ్విని.అశ్విని
            地址:అశ్విని
            性别:అశ్విని
            电话: {
                手机:అశ్విని
                家:అశ్విని
                办公室:రేవతి
            }
    },
    {
            ID:C201,
            名:అశ్విని公羊
            电子邮件:అశ్విని@అశ్విని.అశ్విని
            地址:అశ్విని
            性别:అశ్విని
            电话: {
                手机:అశ్విని
                家:అశ్విని
                办公室:అశ్విని
            }
    }
]
}

以下是code I用于检索数据。

 公共类JSONParser {静态InputStream为= NULL;
静态的JSONObject jObj = NULL;
静态JSON字符串=;//构造
公共JSONParser(){}公众的JSONObject getJSONFromUrl(字符串URL){    //使HTTP请求
    尝试{
        // defaultHttpClient
        DefaultHttpClient的HttpClient =新DefaultHttpClient();
        HttpPost httpPost =新HttpPost(URL);        HTT presponse HTT presponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = HTT presponse.getEntity();
        是= httpEntity.getContent();    }赶上(UnsupportedEncodingException五){
        e.printStackTrace();
    }赶上(ClientProtocolException E){
        e.printStackTrace();
    }赶上(IOException异常五){
        e.printStackTrace();
    }    尝试{
        读者的BufferedReader =新的BufferedReader(新的InputStreamReader(是,ISO-8859-1),8);
        StringBuilder的SB =新的StringBuilder();
        串线= NULL;
        而((行= reader.readLine())!= NULL){
            sb.append(行+\\ n);
        }
        is.close();
        JSON = sb.toString();
    }赶上(例外五){
        Log.e(缓冲区错误,错误转换结果+ e.toString());
    }    //尝试分析字符串到一个JSON对象
    尝试{
        jObj =新的JSONObject(JSON);
    }赶上(JSONException E){
        Log.e(JSON解析器,错误分析数据+ e.toString());
    }    //返回JSON字符串
    返回jObj;}
}


解决方案

您需要使用NTR.TTF字体中的资产文件夹,并应改变以下

 的BufferedReader读者=新的BufferedReader(新的InputStreamReader(是,UTF-8),8000);

Is it possible to retrieve text written in telugu from the server for use in application. I have used the below format for Json. It is giving me error in some symbols at the logcat of the avd. If not which would be suitable for getting such kind of text.

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

The following is the code i used to retrieve data

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;

}
}

解决方案

You need to use NTR.TTF font in the assets folder and should change the line below

BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8000);

这篇关于使用JSON泰卢固文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆