Json数据库链接

时间:2015-07-31 16:35:19

标签: php html mysql json database

大家好我是处理PHP和JSON的问题

这是我的php代码

<?php

    mysql_connect("127.0.0.1","root","");
    mysql_select_db("spadramatico_db");

    $query = mysql_query("SELECT * FROM feed_table ORDER BY id");
    $records = array();

    while($obj = mysql_fetch_object($query)) {
        $records [] = $obj;
    }
    print (json_encode($records));

?>

这是输出结果:

[{"id":"1","title":"Teste Title","image":"http:\/\/catalinaseaspa.com\/wp-content\/uploads\/2015\/03\/island-girl.jpg","desc":"Desc test","price":"1"}]

我的问题与链接有关,输出如下:

http:\/\/catalinaseaspa.com\/wp-content\/uploads\/2015\/03\/island-girl.jpg

但它是这样的:

http://catalinaseaspa.com/wp-content/uploads/2015/03/island-girl.jpg

我该如何解决? 谢谢:D

1 个答案:

答案 0 :(得分:0)

试试这段代码。将JSON_UNESCAPED_SLASHES添加到函数中。

<?php
    mysql_connect("127.0.0.1","root","");
    mysql_select_db("spadramatico_db");

    $query = mysql_query("SELECT * FROM feed_table ORDER BY id");
    $records = array();

    while($obj = mysql_fetch_object($query)) {
        $records [] = $obj;
    }
    print (json_encode($records,JSON_UNESCAPED_SLASHES));

?>