json 문자열에 사용자가 입력 한 텍스트를 저장하는 응용 프로그램이 있습니다. 그런 다음 해당 json 문자열을 파일에 저장합니다. 그리고 나서 나중에 파일을 읽어서 json 문자열을 추출하고 마지막으로 문자열을 textview에 표시하여 다시 표시하십시오. 그러나 나는 £, ÷, € 등의 특수 문자 (오히려 기호)가 다시 표시되지 않는다는 사실을 알고 있습니다. 예를 들어, € 기호는 €로 표시됩니다.json 문자열의 특수 문자 처리 방법
참조 아래에 몇 가지 예제 코드
먼저 사용자가 입력 한 텍스트를 캡처하고 파일에서 다시 문자열을 가져 오기위한 코드 아래
//get user entered text
QuestionEditText = (EditText)this.findViewById(R.id.editTextQuestion);
//put that into json object
JSONObject jObjOneQuestionDetails=new JSONObject();
jObjOneQuestionDetails.put("Question", QuestionEditText.getText());
//write json object into file
FileOutputStream output = openFileOutput("MyFileName",MODE_PRIVATE);
OutputStreamWriter writer = new OutputStreamWriter(output);
writer.writejObjOneQuestionDetails.put());
writer.flush();
writer.close();
이제 파일로 넣고에 표시하기위한 코드 사용자
위의 코드는 단지 샘플입니다//define and initialize variables
QuestionEditText = (EditText)this.findViewById(R.id.editTextQuestion);
private JSONArray jArrayQuizQuestions=new JSONArray();
private JSONObject jObjQuizTitle=new JSONObject();
//load JSONObject with the File
int ch;
StringBuffer fileContent = new StringBuffer("");
FileInputStream fis;
String fileString;
fis = this.getBaseContext().openFileInput("MyFileName");
while((ch = fis.read()) != -1)
fileContent.append((char)ch);
fileString = new String(fileContent);
jObjQuizTitle = new JSONObject(fileString);
jArrayQuizQuestions = jObjQuizTitle.getJSONArray("MyFileName");
//display json object into textview
JSONObject aQues = jArrayQuizQuestions.getJSONObject(pageNumber-1);
String quesValue = aQues.getString("Question");
QuestionEditText.setText(quesValue.toCharArray(), 0, quesValue.length());
, 나는 여기에 어떤 시도/catch 블록을 무시했다. 이렇게하면 사용자가 입력 한 텍스트를 캡처하고 표시하는 방법에 대한 아이디어를 얻을 수 있습니다.
어쩌면 듭니다 귀하의 문자 인코딩에 문제가 있습니다. 코드는 어떻게 생겼습니까? – hakanostrom