2014-04-07 5 views
2

PHP 웹 서비스의 JSON 응답에서 어포 스트로피 대신 & # 039가 표시됩니다. 어떻게 JSON 응답을 안드로이드의 특수 문자로 파싱 할 수 있습니까?webservices에서 json 응답의 특수 문자를 구문 분석하십시오.

편집

내 HTTP 연결 방법 코드 -

InputStream is = null; 
    String response = null,value = null; 
    try { 
     DefaultHttpClient httpClient = new DefaultHttpClient(); 
     HttpGet httpPost = new HttpGet(url);  
     HttpResponse httpResponse = httpClient.execute(httpPost); 
     HttpEntity httpEntity = httpResponse.getEntity(); 
     is = httpEntity.getContent(); 
    } 
    catch (UnknownHostException e) { 
     e.printStackTrace(); 
    } 
    catch (UnsupportedEncodingException e) { 

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

     e.printStackTrace(); 
    } 


    try { 
     BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8); 
     String line = null; 
     while ((line = reader.readLine()) != null) { 
      value=line.trim(); 
     } 
     is.close(); 
     response = URLEncoder.encode(value,"UTF-8"); 
    } catch (Exception e) { 
     Log.e("Buffer Error", "Error converting result " + e.toString()); 
    } 

응답에 영향 URLDecoder 적용하고 응답 URLEncoder와 함께 할 때 일부 기호 및 추가 숯불 % 20D (같은 appeded 있습니다 /). 우리가 이것을 할 수있는 html로 클래스를 사용

+0

URLDecoder를 사용하여 –

+0

URL을 제공해주십시오. –

답변

0

첫째, 당신은 HTML의 세그먼트를 얻을 참조하십시오 순수 POJO가 아닌 웹 서비스의 텍스트.

두 번째로 URLEncoder 또는 URLEncoder가 & #XXX 유형을 이스케이프하는 데 도움이되지 않으면 " '"을 (를) % 27로, ","을 % 2C (으)로 이스케이프합니다.

마지막 fromHTML는 HTML 문자열을 구문 분석 트릭을 수행, API는 android.text.HTML 객체의

public static Spanned fromHtml(String source); 

입니다.

HTML.fromHTML("&#039") 

의 반환 값은 '' '입니다.

관련 문제