我正在使用Java。這是被插入數據存儲中的純數據:Google App Engine - 以奇怪的方式存儲數據
<p>Something</p>\n<p>That</p>\n<p> </p>\n<p>Should.</p>\n<p> </p>\n
<p>I have an interesting question.</p>\n<p>Why are you like this?</p>\n
<p> </p>\n<p>Aren't you fine?</p>
這是它如何被存儲:
<p>Something</p> <p>That</p> <p>�</p> <p>Should.</p> <p>�</p>
<p>I have an interesting question.</p> <p>Why are you like this?</p>
<p>�</p> <p>Aren't you fine?</p>
怎麼了怪異的符號?這隻會發生,而不是我的本地dev_appserver。
編輯
下面是插入數據代碼:
String content = ""; // this is where the data is stored
try {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);
while(iter.hasNext()) {
FileItemStream item = iter.next();
InputStream stream = item.openStream();
if(item.isFormField()) {
String fieldName = item.getFieldName();
String fieldValue = new String(IOUtils.toByteArray(stream), "utf-8");
LOG.info("Got a form field: " +fieldName+" with value: "+fieldValue);
// assigning the value
if(fieldName.equals("content")) content = fieldValue;
} else {
...
}
}
} catch (FileUploadException e){
}
...
// insert it in datastore
Recipe recipe = new Recipe(user.getKey(), title, new Text(content), new Text(ingredients), tagsAsStrings);
pm.makePersistent(recipe);
這是一個multipart/form-data
形式,所以我必須做的那個小item.isFormField()
魔術獲得實際的內容,並創建一個字符串。也許這是造成奇怪的編碼問題?不確定。
要檢索,我只是做數據:
<%=recipe.getContent().getValue()%>
由於content
是Text類型(應用引擎式)我用.getValue()
獲得實際的結果。我不認爲這是檢索數據的問題,因爲我可以直接在在線應用程序引擎數據存儲區查看器中看到奇怪的字符。
\ n是新行的指標。這是你指的是什麼? – 2011-04-18 19:58:52
這是99%的編碼問題;你在代碼中如何處理編碼?你能發佈一些相關的片段嗎? – systempuntoout 2011-04-18 20:00:50
@systempuntoout:我沒有處理它。有什麼特別的我*需要*做? – 2011-04-18 20:10:47