how to remove escape slash from string in android

百般思念 提交于 2019-12-12 04:29:00

问题


I have tried all possible solution but couldn't find any answers.

I have following string.

"{\"property_type\":[\"residential\"],\"status\":[\"active\"],\"category\":[\"sale\"],\"page_size\":8,\"cur_page\":1}"

This is response I am getting from json.

Please help me with this concern.


回答1:


You may try this if you want to remove escape slash from android ....

String receivedString = "{\"property_type\":[\"residential\"],\"status\":[\"active\"],\"category\":[\"sale\"],\"page_size\":8,\"cur_page\":1}";

    String changedString = receivedString.replaceAll("\"", "\"");
    Log.d("your_tag", changedString);

Output will be like below :

{"property_type":["residential"],"status":["active"],"category":["sale"],"page_size":8,"cur_page":1}



回答2:


myString.replaceAll("\\/","");



回答3:


$postdata = stripslashes("[".$_POST["data"]."]");
$data = json_decode($postdata,true);
try{
if(is_array($data)){
    foreach ($data as $row) {
        $line1 = $row['line1'];
        $line2 = $row['line2'];
        $line3 = $row['line3'];
        $line4 = $row['line4'];
    }
}
}catch(Exception $e){

}

here i am passing the data from my android app to my server and decode the values using the above code successfully

hope it helps to you...




回答4:


yesss finally this works for me :

//delete backslashes ( \ ) :
            data = data.replaceAll("[\\\\]{1}[\"]{1}","\"");
//delete first and last double quotation ( " ) :
            data = data.substring(data.indexOf("{"),data.lastIndexOf("}")+1);
            JSONObject json = new JSONObject(data);


来源:https://stackoverflow.com/questions/40693393/how-to-remove-escape-slash-from-string-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!