Home backslash being add to url of array after json_encode
Reply: 2

backslash being add to url of array after json_encode

aamir ali
aamir ali Published in 2018-02-14 09:31:23Z

Actually I am using php codeigniter as a server side language.So when I am try to send the array to android application using json_encode the unwanted backslash being added every time in the user_image url only but the other data of array remain unchanged.

here is my php codeigniter controller code.

class Groups extends CI_Controller
    public function groupmember()
        echo json_encode($data,JSON_UNESCAPED_SLASHES);

here is my php codeigniter model code.

class Groups_Model extends CI_Model
   public function groupmemberlist($session_id)
        $where = "sender_id='".$session_id." AND request_status=1 ' OR receiver_id='".$session_id."' AND request_status=1";
        $query =$this->db->get();
        foreach($query->result_array() as $row)

        return $data;
   function friendlist($userid)
      return $query->result_array();

this is how I am getting the response in android.

        "user_id": "7",
        "auth_id": "109236658041750871608",
        "full_name": "Abdullah Khaled",

        "email_id": "abdullahkhaled604@gmail.com",

        "image_url": "https:\/\/lh5.googleusercontent.com\/-G9ZMVsph4no\/AAAAAAAAAAI\/AAAAAAAAAAA\/ACSILjX8pu4sXdCmwpUrFTgcRjXT4iwD-w\/s96-c\/photo.jpg"

and after getting this response activity get closed.

I have also tried in android side to replace the backslash but it not worked for me.

below code i have tried to replace the backslash in android.

String myUrl = json_date.getString("image_url");
        //myUrl = myUrl.replaceAll("\\\\", "");

I get stucked in from two days so please help. thanks in advance.

Hasta Dhana
Hasta Dhana Reply to 2018-02-14 10:07:11Z

Try replacing :

echo json_encode($data,JSON_UNESCAPED_SLASHES);


echo str_replace('\/','/',json_encode($data));
user7596840 Reply to 2018-02-14 10:22:16Z

Try this

     $str = 'https://lh5.googleusercontent.com/-G9ZMVsph4no/AAAAAAAAAAI/AAAAAAAAAAA/ACSILjX8pu4sXdCmwpUrFTgcRjXT4iwD-w/s96-c/photo.jpg';
     $str_encode = json_encode($str);
     $str_decode = json_decode($str_encode ,TRUE);
     echo $str_encode .'<br>' ;
      echo $str_decode;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.322927 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO