Skip to content

Instantly share code, notes, and snippets.

@lucas1
Created May 29, 2015 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucas1/befe7c5b6aec71c925e5 to your computer and use it in GitHub Desktop.
Save lucas1/befe7c5b6aec71c925e5 to your computer and use it in GitHub Desktop.

Class WJSON Documentation

Description

Write JSON with simplicities

construct

$wjson = new WJSON( set encoding, set variable )

$wjson = new WJSON;

or

$wjson = new WJSON([encoding => 'ISO-8859-1', variable => 'json']);

Objects

$wjson->Objects( [ 'key attribute' => 'value attribute' ] )

$wjson->Objects(
    [
        "id" => 01,
        "sales" => "35",
        "year" => "'07"
    ]
);

header

$chart->header()

$chart->header();

return

header("Content-type: application/xml; charset=utf-8");

result

$chart->result()

echo $chart->result();

Print XML

Examples

Example 1

<?php
include_once 'DHX.php';

$chart = new Chart;

$chart->item(
    array(
        "id" => 01,
        "sales" => "35",
        "year" => "'07"
    ),
    array(
        "id" => 11,
        "sales" => "50",
        "year" => "'08"
    ),
    array(
        "id" => 21,
        "sales" => "65",
        "year" => "'09"
    ),
    array(
        "id" => 31,
        "sales" => "30",
        "year" => "'10"
    ),
    array(
        "id" => 41,
        "sales" => "45",
        "year" => "'11"
    )
);

$chart->header();
echo $chart->result();
?>

Result

<?xml version="1.0" encoding="utf-8"?>
<data>
    <item id="1">
        <sales>35</sales>
        <year>'07</year>
    </item>
    <item id="11">
        <sales>50</sales>
        <year>'08</year>
    </item>
    <item id="21">
        <sales>65</sales>
        <year>'09</year>
    </item>
    <item id="31">
        <sales>30</sales>
        <year>'10</year>
    </item>
    <item id="41">
        <sales>45</sales>
        <year>'11</year>
    </item>
</data>

Author

Lucas Tiago de Moraes

Support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment