2014-02-18 8 views
0

enter image description here 나는 표시 PHP MySQL 서버의 데이터베이스에서 JSON의 URL 및 데이터 저장소에서 일부 구자라트어 ​​텍스트를 텍스트보기가 응용 프로그램을 개발 너무 디스플레이 구자라트어 ​​글꼴에 문제JSON 구문 분석 문제가

JSON에 http 내 코드는

public class CustomHttpClient { 


    public static final int HTTP_TIMEOUT = 30 * 1000; 

    private static HttpClient mHttpClient; 




private static HttpClient getHttpClient() { 

    if (mHttpClient == null) { 
    mHttpClient = new DefaultHttpClient(); 

    final HttpParams params = mHttpClient.getParams(); 
    HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT); 
    HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT); 
    ConnManagerParams.setTimeout(params, HTTP_TIMEOUT); 
    } 

    return mHttpClient; 
} 

public static String executeHttpPost(String url,ArrayList<NameValuePair> postParameters) throws Exception { 

     BufferedReader in = null; 

     try { 

     HttpClient client = getHttpClient(); 

     HttpPost request = new HttpPost(url); 

     UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
     postParameters); 

     request.setEntity(formEntity); 

     HttpResponse response = client.execute(request); 

     in = new BufferedReader(new InputStreamReader(response.getEntity() 
     .getContent())); 


    // in = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8000); 
     StringBuffer sb = new StringBuffer(""); 

     String line = ""; 

     String NL = System.getProperty("line.separator"); 

     while ((line = in.readLine()) != null) { 

     sb.append(line + NL); 

     } 

     in.close(); 
     String result = sb.toString(); 
     return result; 

     } finally { 

    if (in != null) { 

    try { 

    in.close(); 

    } catch (IOException e) { 

    Log.e("log_tag", "Error converting result "+e.toString()); 

    e.printStackTrace(); 

    } 

    } 

    } 

} 

여기에 주요 활동 코드 ... ... 여기

desc_about=(TextView)v.findViewById(R.id.textdesc); 

Typeface tf=Typeface.createFromAsset(getActivity().getAssets(),"Shruti.ttf"); 
     desc_about.setTypeface(tf); 

ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); 

postParameters.add(new BasicNameValuePair("temple_id","2")); 



String response = null; 

      try {    
         response = CustomHttpClient.executeHttpPost(
         url_temple,postParameters); 

         String result = response.toString(); 

     try { 
       JSONArray jArray = new JSONArray(result); 
       for(int i=0;i<jArray.length();i++) 
       { 
        JSONObject json_data = jArray.getJSONObject(i); 
        about_temple=json_data.getString("about_text"); 
      } 

     } 
     catch(JSONException e){ 
       Log.e("log_tag", "Error parsing data "+e.toString()); 
     } 

} 

     try{ 


      desc_about.setText(about_temple); 


     } 
     catch(Exception e){ 
      Log.e("log_tag","Error in Display!" + e.toString());; 
      Toast.makeText(getActivity(), "error" + 2, 100).show(); 
     } 
      } 
      catch (Exception e) { 
    Log.e("log_tag","Error in http connection!!" + e.toString()); 
    Toast.makeText(getActivity(), "error" + 3, 100).show(); 
    } 
+0

이 줄을 사용하십시오. 새로운 BufferedReader (새로운 InputStreamReader (iso-8859-1), 8); –

+0

은 .......입니까? –

+0

널 포인터 null 예외 예외 –

답변

0

사용해보십시오 UTF-endcoding시 PHP 측에서 JSON을 만들고 안드로이드 측에서 utf를 디코딩하는 것과 같은 방법. 나는이 방법을 사용하여 iOS 응용 프로그램에서 해결했습니다. 감사합니다.

+0

에 u 샘플 코드가 있습니까? 고맙습니다 –