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
1#
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()
    {
        $this->load->model("Groups_Model");
        $data['memberlist']=$this->Groups_Model->groupmemberlist($this->input->post('user_id'));
        //die(print_r($data));
        if($data!=null)
        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)
   {
       $this->load->database();
        $this->db->select("*");
        $this->db->from("circle");
        $where = "sender_id='".$session_id." AND request_status=1 ' OR receiver_id='".$session_id."' AND request_status=1";
        $this->db->where($where);
        $query =$this->db->get();
        foreach($query->result_array() as $row)
        {
            if($row['sender_id']==$session_id)
            {
                $data[]=$this->friendlist($row['receiver_id']);
            }
            else
            {
                $data[]=$this->friendlist($row['sender_id']);
            }
        }

        if(!empty($data))
        return $data;
   }
   function friendlist($userid)
   {
      $this->load->database();
      $this->db->select('*');
      $this->db->from('users');
      $this->db->where('auth_id',$userid);
      $query=$this->db->get();
      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
2#
Hasta Dhana Reply to 2018-02-14 10:07:11Z

Try replacing :

echo json_encode($data,JSON_UNESCAPED_SLASHES);

with

echo str_replace('\/','/',json_encode($data));
user7596840
3#
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