Stream.Publish,Android,Facebook中包含“”的字符串问题

时间:2010-12-28 11:46:29

标签: android facebook

我正试图通过我改编的FBConnect(与http://www.mobisoftinfotech.com/blog/android/845/类似的东西)在Facebook墙上发帖,我遇到了包含“”

的字符串的问题
public void postToWall(String message){
     Bundle parameters = new Bundle();
     parameters.putString("message", message);

     String attachment;

     if (website == null) {
      attachment = "{\"name\":\""+ name + "\"," +
   "\"description\":\""+ description + "\"" +       
   "}";
     }
     else {
      attachment = "{\"name\":\""+ name + "\"," +
       "\"href\":\"" + website + "\"," +
       "\"description\":\""+ description + "\"" +       
       "}";
     }
     parameters.putString("attachment", attachment);

E.G。如果描述是'lorem ipsum'它的工作非常好但是例如如果描述是'lorem ipsum'blhe“bazooka”而不是它不起作用。

我已经尝试过这样编码附件

parameters.putString("attachment", URLEncoder.encode(attachment));

但我得到了相同的结果。 编辑:实际上使用URLEncoder它根本不起作用..

关于如何解决这个问题的任何想法?

谢谢。

1 个答案:

答案 0 :(得分:1)

尝试使用apache commons中的escapeHtmlhttp://commons.apache.org/lang/api-2.4/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml%28java.io.Writer,%20java.lang.String%29 并将该方法应用于可能包含不需要的字符的所有变量。

attachment = "{\"name\":\""+ StringEcapeUtils.escapeHtml(name) + "\"," + "\"description\":\""+ StringEcapeUtils.escapeHtml(description) + "\"" +
"}";