0

I want to display hindi characters using textview in android which are json response from specified url. the json response in glassfishserver output screen looks like this

{"combo":[{"qid":"7H1","qstn":"? - ? ??","ans":"?","op1":"?","op2":"?"}]}

where each ? mark is a hindi character.

In android it shows something like this àô-àô??

All these hindi texts are stored in mysql as utf8.

{con = DriverManager.getConnection("jdbc:mysql://localhost:3306/edupad? ?useUnicode=true&characterEncoding=UTF-8", "root", "root");}

when directly the hindi text set to the textview using the code

textview.settext("क - म ??"); it displays the hindi characters properly.

What should i do to display hindi characters from url properly in android..???

the jsp page is given below

 <%@page import="com.edupad.quiz_list"%>
<%@page import="com.edupad.Lang_List"%>
<%@page import="com.google.gson.Gson"%>
<%@page import="com.edupad.dbclass"%>
<%@page import="com.edupad.Language_bean"%>
<%@page import="com.sun.org.apache.bcel.internal.generic.LAND"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/edupad?        useUnicode=yes&characterEncoding=utf-8", "root", "root");;
      Statement s = cn.createStatement();

    ResultSet re = s.executeQuery("select * from language_tab");

  Gson gn = new Gson();



    String lang = request.getParameter("lang");
    System.out.println("lang=" + lang);

    String type = request.getParameter("type");
    System.out.println("type=" + type);
    List<quiz_list> lst = new ArrayList<quiz_list>();
    //   lst = db.reqst_qstns(lang, type);

    try {
        String q = "select qid,qstn,answer,op1,op2 from quiz_tab,language_tab,type_tab where         quiz_tab.lid=language_tab.lid and quiz_tab.tid=type_tab.tid and type_tab.type_name='" + type + "' and language_tab.lang_name='" + lang + "'";

        System.out.println("q=" + q);
        re = s.executeQuery(q);

        while (re.next()) {


            lst.add(new quiz_list(re.getString(1), re.getString(2), re.getString(3), re.getString(4), re.getString(5)));

        }

    } catch (Exception ex) {
        System.out.println("@reqst_example" + ex);
    }



    System.out.println("lst size=" + lst.size());



    String msg = gn.toJson(lst);


    out.println("{\"combo\":" + msg + "}");

    System.out.println("{\"combo\":" + msg + "}");

} catch (Exception ex) {
    System.out.println("@reqst_example" + ex);
}
 %>

Function to get json response is given below

try {
        ArrayList<NameValuePair> npv = new ArrayList<NameValuePair>();

        npv.add(new BasicNameValuePair("lang", lang));
        npv.add(new BasicNameValuePair("type", type));


        

        String url = "http://" + ip.trim() + ":8080/edupad/faces/questions.jsp";


        jsonparser jp = new jsonparser();
        JSONObject jsson = jp.getJSONfromURL(url,    getApplicationContext().getApplicationContext(), npv);
        JSONArray jSONArray = jsson.getJSONArray("combo");
      
        qstns = new String[jSONArray.length()];
        ans = new String[jSONArray.length()];
        op1 = new String[jSONArray.length()];
        op2 = new String[jSONArray.length()];
        r = new int[jSONArray.length()];
        for (int d = 0; d < jSONArray.length(); d++) {
            JSONObject jsn = jSONArray.getJSONObject(d);
                     
            qstns[d]=jsn.getString("qstn");
            ans[d] = jsn.getString("ans");
            op1[d] = jsn.getString("op1");
            op2[d] = jsn.getString("op2");

        }
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), " exc==" + e, Toast.LENGTH_LONG).show();
    }
}
Community
  • 1
  • 1
shahana
  • 1
  • 1

0 Answers0