在Android中通过JSONObject传递转换为\ /转换为/

时间:2013-11-06 17:11:56

标签: android jsonobject

我有一个放入JSONObject的字符串。它在传递之前看起来像这样:

  Before: /storage/sdcard/Download/signature-1383757302516.jpg

  After: \/storage\/sdcard\/Download\/signature-1383757302516.jpg

以下是我的代码:

   // make JSON object to hold the information, which is sent to the server
  JSONObject jsonObjSend = new JSONObject();
  jsonObjSend.put("signature", signatureFile.getAbsolutePath())

jsonObjSend()。toString()的输出是:

  \/storage\/sdcard\/Download\/signature-1383757302516.jpg

JSONOBject是否编码信息?如何防止它修改正斜杠?

*编辑: 我使用正则表达式解决了它以删除转义字符。

  jsonObjSend.toString().replaceAll("\\\\/", "/")

1 个答案:

答案 0 :(得分:0)

toString()方法通常在复杂对象上调用时返回带有转义字符的值。你的价值存储得很好。试着打电话

jsonObjSend.get("signature");