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

backslash being add to url of array after json_encode

user2720
1#
user2720 Published in August 16, 2018, 6:14 am

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.

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO