[英]how to remove escape slash from string in android
我已经尝试了所有可能的解决方案,但找不到任何答案。
我有以下字符串。
"{\"property_type\":[\"residential\"],\"status\":[\"active\"],\"category\":[\"sale\"],\"page_size\":8,\"cur_page\":1}"
这是我从 json 得到的回应。
请帮我解决这个问题。
myString.replaceAll("\\/","");
$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){
}
在这里,我将数据从我的 android 应用程序传递到我的服务器并使用上述代码成功解码值
希望对你有帮助...
如果你想从 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);
输出将如下所示:
{"property_type":["residential"],"status":["active"],"category":["sale"],"page_size":8,"cur_page":1}
是的,这最终对我有用:
//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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.