在JSON中显示URL

时间:2013-06-06 17:08:17

标签: mysql json

我从json开始服务但是我有问题在json中显示url,这个url http://git.drieanto.net/LagiDimanaAPI/index.php/user/get_following/1我试图从数据库中显示url但是在json show "avatar":"http:\/\/git.drieanto.net\/LagiDimanaAPI\/assets\/image\/avatar\/edwin.png"中。

如何显示正常的网址,例如http://git.drieanto.net/LagiDimanaAPI/assets/image/avatar/edwin.png

我使用codeigniter这个代码

function get_following($id_follower) {
        if ($this->muser->cek_following($id_follower) == TRUE) {
            $query = $this->muser->get_list_id($id_follower);

            $feedback["following"] = array();

            foreach ($query->result() as $row) {

                $query_list_user = $this->muser->get_all_name_user_from_id($row->id_user);

                if ($query_list_user->num_rows() > 0) {

                    $row_ = $query_list_user->row();

                    $query_status = $this->muser->get_status($row_->id_user);
                    $query_status->num_rows();
                    $row2 = $query_status->row();
                    $response['status'] = $row2->status;

                    $response['regid'] = $row_->regid;

                    $response['id_user'] = $row_->id_user;

                    $response['email'] = $row_->email;

                    $response['nama'] = $row_->nama;

                    $response['jenis_kelamin'] = $row_->jenis_kelamin;

                    $response['tanggal_lahir'] = $row_->tanggal_lahir;

                    $response['instansi'] = $row_->instansi;

                    $response['jabatan'] = $row_->jabatan;

$response['avatar'] = $row_->avatar;

                    $feedback['success'] = 1;
                } else {

                    $feedback['success'] = 0;
                }
                array_push($feedback["following"], $response);
            }
            $feedback['success'] = 1;
            echo json_encode($feedback);
        } else {
            $feedback['success'] = 0;
            echo json_encode($feedback);
        }
    }

感谢

1 个答案:

答案 0 :(得分:0)

它只是逃避了前锋。您可以使用str_replace($search_char, $replace_char, $string_to_search),删除它们。

$stuff = json_decode($response);
$url = str_replace("\\", "", $stuff['url']);

听起来好像你没有解码JSON,因为我相信PHP会自动为你解决所有这些问题。