在android上的sqlite中单引号

我从webservice获得了价值.我的一些价值观带有单引号.像这个样本的sqlite不支持单引号.所以我用双引号替换它们.然后我从db中检索值,我无法解析该值.我得到解析器异常不正常.谁能告诉我怎么做?

这是我的代码替换双引号的单引号

              stockservicevalue=stockservicevalue.replaceAll("'", "\"");

这是我从db检索的值

String sql = "SELECT * FROM MyQuest;";

日志:

03-28 19:02:36.309: WARN/System.err(344): org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 50437: not well-formed (invalid token)
03-28 19:02:36.321: WARN/System.err(344):     at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:492)
03-28 19:02:36.330: WARN/System.err(344):     at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:477)
03-28 19:02:36.340: WARN/System.err(344):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:317)
03-28 19:02:36.380: WARN/System.err(344):     at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:273)
03-28 19:02:36.389: WARN/System.err(344):     at com.inquest.SaxPortfolioDocument.getEventsFromAnXML(SaxPortfolioDocument.java:13)
03-28 19:02:36.411: WARN/System.err(344):     at com.inquest.PortfolioActivity$PortFolioTask.doInBackground(PortfolioActivity.java:171)
03-28 19:02:36.420: WARN/System.err(344):     at com.inquest.PortfolioActivity$PortFolioTask.doInBackground(PortfolioActivity.java:1)
03-28 19:02:36.430: WARN/System.err(344):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-28 19:02:36.430: WARN/System.err(344):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-28 19:02:36.440: WARN/System.err(344):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-28 19:02:36.479: WARN/System.err(344):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-28 19:02:36.500: WARN/System.err(344):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-28 19:02:36.510: WARN/System.err(344):     at java.lang.Thread.run(Thread.java:1096)
03-28 19:02:36.840: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@46dfec78

谢谢

解决方法:

stockservicevalue=stockservicevalue.replaceAll("'", "\''"); 
上一篇:java – 在Soap Request中发送无效的XML字符


下一篇:如何在存储为Javascript变量的HTML字符串中转义JSON?