json语法要求很严格,如果你在传递json字符串的时候,包含了特殊字符,如:
空格、回车、换行、制表。。。。。。
那么在用JSONObject.fromObject()转换时,就会报:
JSON Exception: Unterminated string at character这样的错误。
解决办法就是,在你转换json格式之前,将一些特殊字符转义,如下:
theString = theString.replace(">", ">");
theString = theString.replace("<", "<");
theString = theString.replace(" ", " ");
theString = theString.replace("\"", """);
theString = theString.replace("\'", "'");
theString = theString.replace("\\", "\\\\");//对斜线的转义
theString = theString.replace("\n", "\\n");
theString = theString.replace("\r", "\\r");