2013-05-30 3 views
1

파일에 JSON 응답을 쓰고 있는데 텍스트 파일에서 JSON 응답을 검색 할 때 json 객체 (실제로 이상한) 앞에 null이 있습니다.앞에있는 값이 null 인 json 응답입니다.

05-30 16:35:16.454: W/System.err(21734): org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONObject 
05-30 16:35:16.454: W/System.err(21734): at org.json.JSON.typeMismatch(JSON.java:111) 
05-30 16:35:16.454: W/System.err(21734): at org.json.JSONObject.<init>(JSONObject.java:158) 
05-30 16:35:16.454: W/System.err(21734): at org.json.JSONObject.<init>(JSONObject.java:171) 

다음은 문자열을 인쇄 할 때 이것을 보여줍니다.

05-30 16:35:16.454: I/json data in ProfileActivity(21734): null{"id":1488,"email":"[email protected]","full_name":"Jon 

다음은 데이터 저장 및 검색 방법입니다.

public void saveToInternal(String data, String name, Context context){ 
     ContextWrapper contextWrapper = new ContextWrapper(context); 
     File directory = contextWrapper.getDir(filepath, Context.MODE_PRIVATE); 
     myInternalFile = new File(directory , name); 
     try { 
      FileOutputStream fos = new FileOutputStream(myInternalFile); 
      fos.write(data.getBytes()); 
      fos.close(); 
      } catch (IOException e) { 
      e.printStackTrace(); 
      } 
     Log.i("data saved", "data named " + name + "saved to directory."); 
} 

public String getInternalData(String filename, Context context){ 
     ContextWrapper contextWrapper = new ContextWrapper(context); 
     File directory = contextWrapper.getDir(filepath, Context.MODE_PRIVATE); 
     myInternalFile = new File(directory , filename); 
    String myData = null; 
    try { 
      FileInputStream fis = new FileInputStream(myInternalFile); 
      DataInputStream in = new DataInputStream(fis); 
      BufferedReader br = 
      new BufferedReader(new InputStreamReader(in)); 
      String strLine; 
      while ((strLine = br.readLine()) != null) { 
      myData = myData + strLine; 
      } 
      in.close(); 
      } catch (IOException e) { 
      e.printStackTrace(); 
      } 

    return myData; 

} 
+0

원본 json 문자열에 null이 추가되어있는 것 같습니다. – Pragnani

+0

이 문자열은 백엔드 문제 – Blackbelt

+0

문자열 분할을 시도했기 때문에 추가되지 않았습니다. null는, 무엇인가의 이유로써, 캐릭터 라인의 전방에 'type'로서 인쇄되고 있습니다. 서버에서 검색 할 때 백엔드 문제가 아닌 임의의 null 값이 포함되어 있습니다. – jimbob

답변

0

나는 그것을 알아 냈다!

줄을 변경했습니다.

String myData = null;

에 :

문자열 MYDATA = "";

myData가 다른 문자열에 추가되었지만 문자열에 null을 추가하면 데이터 앞부분에 이상한 이동식 null 값이 생깁니다.

관련 문제