Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Problemi struttura JSON

    ciao!
    dovrei creare un file che esponga i dati in json in questo formato:
    codice:
    {
        "success": 1,
        "result": [
            {
                "id": "293",
                "title": "This is warning class event with very long title to check how it fits to evet in day view",
                "url": "http://www.example.com/",
                "class": "event-warning",
                "start": "1362938400000",
                "end":   "1363197686300"
            },
            {
                "id": "256",
                "title": "Event that ends on timeline",
                "url": "http://www.example.com/",
                "class": "event-warning",
                "start": "1363155300000",
                "end":   "1363227600000"
            }
        ]
    }
    prendendoli da db non riesco a capire come dargli quella struttura:
    Codice PHP:
    <?php

    include_once '../lib/costanti_file.php';

    $appuntamenti = new Appuntamenti(Connessione::getInstance());
    $rows = array();
    $rows['success'] = 1;
    $rows['result'] = '[';
    foreach (
    $appuntamenti->getAppuntamenti() as $a) {
        
    $rows[] = array(
            
    'id' => $a['ap_id'],
            
    'title' => $a['ap_titolo'],
            
    'url' => '',
            
    'class' => 'event-warning',
            
    'start' => '1362938400000',
            
    'end' => '1363227600000'
        
    );
    }
    // CHIUSURA QUADRA ??
    echo json_encode($rows);
    avete qualche idea??

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    E l'echo cos'è che stampa?

  3. #3
    per ora stampa questo:
    codice:
    {"success":1,"result":"[","0":
    {"id":"1","title":"prova  1","url":"","class":"eventwarning","start":"1362938400000",
    "end":"1363227600000"},
    "1":{"id":"3","title":"prova   3","url":"","class":"event-warning","start":"1362938400000","end":"1363227600000"},
    "2":{"id":"2","title":"prova   2","url":"","class":"event-warning","start":"1362938400000","end":"1363227600000"}}
    che non è corretto.
    solo che non riesco a correggerlo.
    ho fatto diversi tentativi ma c'è sempre qualcosa che nn va.
    Ultima modifica di fermat; 10-03-2014 a 14:51

  4. #4
    ok così:
    Codice PHP:
    <?php

    include_once '../lib/costanti_file.php';

    $appuntamenti = new Appuntamenti(Connessione::getInstance());
    $rows = array();
    $rows['success'] = 1;
    $rows['result'] = '';
    foreach (
    $appuntamenti->getAppuntamentiCalendar() as $a) {
        
    $rows['result'][] = array(
            
    'id' => $a['ap_id'],
            
    'title' => $a['ap_titolo'],
            
    'url' => '',
            
    'class' => 'event-warning',
            
    'start' => $a['ux_data'],
            
    'end' => '1363227600000'
        
    );
    }
    echo 
    json_encode($rows);
    ciao!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.