The string "Text1 / Text2" is replaced by "Text1 \ / Text2" in android

When I try to run this code in android, I get the resulting string as "Name":"Text1\/Text2"But the result should be {"Name":"Text1/Text2"}.

try {
    String str;
    JSONObject json = new JSONObject();

    json.put("Name", "Text1/Text2");

    str = json.toString();
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Thanks.

+4
source share
1 answer

@GrlHu , utf-8, / \/.
,
1. JSON: ? 2. JSON -?
getString(Name). , .

try {
    String str;
    JSONObject json = new JSONObject();

    json.put("Name", "Text1/Text2");
    str = json.getString("Name");
    Log.e("test", str);
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
+5

All Articles