Conflict with the generation of JSON

0

I have this layout of a JSON file, which I should follow:

{
    "data": [
        {
            "id": 1,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.541599,
            "longitude": -0.112588,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 1
        },
        {
            "id": 2,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.538395,
            "longitude": -0.097418,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 2
        },
        {
            "id": 3,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.551489,
            "longitude": -0.067077,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 3
        },
        {
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.539212,
            "longitude": -0.118403,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 4
        },
        {
            "id": 5,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.522340,
            "longitude": -0.037894,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 5
        },
        {
            "id": 6,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.503965,
            "longitude": -0.058837,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 6
        },
        {
            "id": 7,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.486758,
            "longitude": -0.112739,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 7
        },
        {
            "id": 8,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.555385,
            "longitude": -0.128274,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 8
        },
        {
            "id": 9,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.560935,
            "longitude": -0.111365,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 9
        },
        {
            "id": 10,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.530189,
            "longitude": -0.078750,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 10
        },
        {
            "id": 11,
            "title": "Clínica Fassina",
            "location": "Clínicos Gerais",
            "latitude": 51.543803,
            "longitude": -0.036607,
            "url": "item-detail.html",
            "type": "<span class='bold_end'>R Francisco Guilherm ...</span> Ver endereço ",
            "type_icon": "flaticon-medical-2",
            "rating": 4,
            "gallery":
                [
                    "images/imagem_padrao.jpg"
                ],
            "date_created": "2014-11-03",
            "price": "<span>(19) 3652-36...</span> Ver telefone",
            "featured": 0,
            "color": "",
            "person_id": 11
        }
    ]
}

The file I used to generate my file is this:

<?php
    /******* Conexão com o bando de dados *******/
    include "../../Conexao/config.php";
    mysqli_select_db($config, $database_config);
    mysqli_set_charset($config,"utf8");
    /******* Conexão com o bando de dados *******/

    $id_resultado       = "2,15,18,66,105,108,233,270,479,651,665";
    $ordem              = ""; 
    $sel_ct_1           = "44"; 
    $cidade_procura_var = "Aguai - SP";
    $icone_sel_geral    = "";
    $icone_cor_geral    = "";

    /* $id_resultado       = $_GET["id_resultado"];
    $ordem              = $_GET["ordem"]; 
    $sel_ct_1           = $_GET["sel_ct_1"]; 
    $cidade_procura_var = $_GET["cidade_procura_var"];
    $icone_sel_geral    = $_GET["icone_sel_geral"];
    $icone_cor_geral    = $_GET["icone_cor_geral"]; */

    if(empty($sel_ct_1)){
        echo "";
    }else{
        $sql_2 = mysqli_query($config, "SELECT id_emp FROM tb_empresas_cat WHERE id_cat = '$sel_ct_1' AND cidade_uf = '$cidade_procura_var'") or die(mysqli_error($config));

        if(@mysqli_num_rows($sql_2) <= '0'){
            echo "";
        }else{
            while($r_sql_2 = mysqli_fetch_array($sql_2)){
                $sel_ct_3[] = $r_sql_2[0];
            }
        }           

        if(empty($sel_ct_3)){
            echo "";
        }else{
            $id_resultado_cat = implode(",",$sel_ct_3);
        }   
    }

    if($ordem == "nome-asc"){
        $sql_json = mysqli_query($config, "SELECT id, razao_social, cep, cidade, uf, rua, numero, bairro, complemento, logo, CodCli FROM tb_empresas WHERE id IN ($id_resultado) AND status = 1 ORDER BY razao_social ASC") or die(mysqli_error($config));
    }elseif($ordem == "nome-desc"){
        $sql_json = mysqli_query($config, "SELECT id, razao_social, cep, cidade, uf, rua, numero, bairro, complemento, logo, CodCli FROM tb_empresas WHERE id IN ($id_resultado) AND status = 1 ORDER BY razao_social DESC") or die(mysqli_error($config));
    }elseif(!empty($sel_ct_1)){
        $sql_json = mysqli_query($config, "SELECT * FROM tb_empresas WHERE id IN ($id_resultado_cat) AND status = 1 ORDER BY plano DESC") or die(mysqli_error($config));
    }else{
        $sql_json = mysqli_query($config, "SELECT id, razao_social, cep, cidade, uf, rua, numero, bairro, complemento, logo, CodCli FROM tb_empresas WHERE id IN ($id_resultado) AND status = 1 ORDER BY plano DESC") or die(mysqli_error($config));
    }

    $return_arr = array();

    if(@mysqli_num_rows($sql_json) <= '0'){
        echo "";
    }else{
        while($r_sql_json = mysqli_fetch_array($sql_json)){
            $id_empresa     = $r_sql_json['id'];
            $endereco     = $r_sql_json['rua'];


            $sql_4 = mysqli_query($config, "SELECT telefone FROM tb_empresas_tel WHERE id_emp = '$id_empresa' ORDER BY telefone ASC LIMIT 1") or die(mysqli_error($config));

            if(@mysqli_num_rows($sql_4) <= '0'){
                echo "";
            }else{
                while($r_sql_4 = mysqli_fetch_array($sql_4)){
                    $telefone_sel   = $r_sql_4[0];
                    $telefone_exibe = substr($telefone_sel, 0, -2);
                }
            }

            $row_array['id']           = $r_sql_json['id'];
            $row_array['title']        = $r_sql_json['razao_social'];
            $row_array['location']     = "Clínicos Gerais";
            $row_array['latitude']     = $r_sql_json['latitude'];
            $row_array['longitude']    = $r_sql_json['longitude'];
            $row_array['url']          = "resultados.php?id_item=$id_empresa";
            $row_array['type']         = "<span class='bold_end'>$endereco ...</span> Ver endereço ";
            $row_array['type_icon']    = $icone_sel_geral;
            $row_array['rating']       = "4";
            $row_array['gallery']      = [ "images/imagem_padrao.jpg" ];
            $row_array['date_created'] = "2014-11-03";
            $row_array['price']        = "<span>(19) $telefone_exibe...</span> Ver telefone";
            $row_array['featured']     =  "0";
            $row_array['color']        =  "";
            //$row_array['person_id']    = $r_sql_json['id'];

            array_push($return_arr,$row_array);         
        }
    }

    echo '{ "data": '.json_encode($return_arr, JSON_NUMERIC_CHECK) . "}";
?>

What is generating this result:

{
  "data":[
    {
      "id":270,
      "title":"MARIA LU\u00cdZA MILANEZ VASCONCELOS",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=270",
      "type":"R Francisco Guilherme ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-25...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":15,
      "title":"ADRIAN OLIVEIRA GUTEMBERG",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=15",
      "type":"R Joaquim de Paula Cruz ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-33...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":18,
      "title":"\u00d4MEGA CENTRO DE REABILITA\u00c7\u00c3O MASCULINA",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=18",
      "type":"R Jos\u00e9 Legaspe ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-54...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":66,
      "title":"ADALBERTO FASSINA",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=66",
      "type":"R Francisco Guilherme ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-20...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":105,
      "title":"CARDIOMED",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=105",
      "type":"R Francisco Guilherme ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-17...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":108,
      "title":"R & M ASSES PSICOLOGICA LTDA - ME",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=108",
      "type":"R Valins ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 99145-02...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":651,
      "title":"CL\u00cdNICA DE ORTOPEDIA ORTOCLIN",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=651",
      "type":"R Francisco Guilherme ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-17...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":665,
      "title":"COMUNIDADE S\u00c3O VICENTE DE PAULO",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=665",
      "type":"R Rui Barbosa ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-14...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":479,
      "title":"CENTRO M\u00c9DICO",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=479",
      "type":"R Joaquim de Paula Cruz ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-33...<\/span> Ver telefone",
      "featured":0,
      "color":""
    },
    {
      "id":233,
      "title":"CL\u00cdNICA HOMEOP\u00c1TICA E INFANTIL S\u00c3O JOS\u00c9",
      "location":"Cl\u00ednicos Gerais",
      "latitude":null,
      "longitude":null,
      "url":"resultados.php?id_item=233",
      "type":"R Vallins ...<\/span> Ver endere\u00e7o ",
      "type_icon":"",
      "rating":4,
      "gallery":[
        "images\/imagem_padrao.jpg"
      ],
      "date_created":"2014-11-03",
      "price":"(19) (19) 3652-29...<\/span> Ver telefone",
      "featured":0,
      "color":""
    }
  ]
}

When I use my solution, there is some conflict (I was able to identify in id ), which causes the site to not function correctly (it's a Google map).

I could not find any differences in PHP-generated JSON and layout.

    
asked by anonymous 28.04.2017 / 03:12

1 answer

0

In addition to the items quoted by Anderson, the coding of your bank seems to be in Latin1 and json is utf8

    
28.04.2017 / 14:00