Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1);
- ini_set('display_errors', 'On');
- header("Content-Type: application/json; charset=utf-8", true);
- class categoryObject
- {
- public $nome;
- public $checked;
- }
- $listItem1 = new categoryObject();
- $listItem1->nome = 'Ristoranti/Pizzerie';
- $listItem1->checked = true;
- $listItem2 = new categoryObject();
- $listItem2->nome = 'Bar';
- $listItem2->checked = true;
- $listItem3 = new categoryObject();
- $listItem3->nome = 'Street Food';
- $listItem3->checked = true;
- $listItem4 = new categoryObject();
- $listItem4->nome = 'Ospitalita';
- $listItem4->checked = true;
- $listItem5 = new categoryObject();
- $listItem5->nome = 'Negozi';
- $listItem5->checked = true;
- $listItem6 = new categoryObject();
- $listItem6->nome = 'Vini e Oli';
- $listItem6->checked = true;
- $listItem7 = new categoryObject();
- $listItem7->nome = 'Pub';
- $listItem7->checked = true;
- $listItem8 = new categoryObject();
- $listItem8->nome = 'Palestre';
- $listItem8->checked = true;
- $loadCategory = array($listItem1, $listItem2, $listItem3, $listItem4, $listItem5, $listItem6, $listItem7, $listItem8);
- $res = $loadCategory;
- try{
- if ( count($res) >=10){
- echo json_encode($res);
- }
- else{
- function json_last_error_msg() {
- static $ERRORS = array(
- JSON_ERROR_NONE => 'No error',
- JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
- JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
- JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
- JSON_ERROR_SYNTAX => 'Syntax error',
- JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
- );
- $error = json_last_error();
- return isset($ERRORS[$error]) ? $ERRORS[$error] : 'Unknown error';
- }
- }
- }
- catch (Exception $e) {
- echo 'Caught exception: ', $e->getMessage(), "\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment