问题
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