Guest User

Untitled

a guest
Feb 29th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <?php
  2. error_reporting(-1);
  3. ini_set('display_errors', 'On');
  4. header("Content-Type: application/json; charset=utf-8", true);
  5. class categoryObject
  6. {
  7. public $nome;
  8. public $checked;
  9. }
  10.  
  11. $listItem1 = new categoryObject();
  12. $listItem1->nome = 'Ristoranti/Pizzerie';
  13. $listItem1->checked = true;
  14.  
  15. $listItem2 = new categoryObject();
  16. $listItem2->nome = 'Bar';
  17. $listItem2->checked = true;
  18.  
  19. $listItem3 = new categoryObject();
  20. $listItem3->nome = 'Street Food';
  21. $listItem3->checked = true;
  22.  
  23. $listItem4 = new categoryObject();
  24. $listItem4->nome = 'Ospitalita';
  25. $listItem4->checked = true;
  26.  
  27. $listItem5 = new categoryObject();
  28. $listItem5->nome = 'Negozi';
  29. $listItem5->checked = true;
  30.  
  31. $listItem6 = new categoryObject();
  32. $listItem6->nome = 'Vini e Oli';
  33. $listItem6->checked = true;
  34.  
  35. $listItem7 = new categoryObject();
  36. $listItem7->nome = 'Pub';
  37. $listItem7->checked = true;
  38.  
  39. $listItem8 = new categoryObject();
  40. $listItem8->nome = 'Palestre';
  41. $listItem8->checked = true;
  42.  
  43.  
  44. $loadCategory = array($listItem1, $listItem2, $listItem3, $listItem4, $listItem5, $listItem6, $listItem7, $listItem8);
  45. $res = $loadCategory;
  46. try{
  47. if ( count($res) >=10){
  48. echo json_encode($res);
  49. }
  50. else{
  51. function json_last_error_msg() {
  52. static $ERRORS = array(
  53. JSON_ERROR_NONE => 'No error',
  54. JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
  55. JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
  56. JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
  57. JSON_ERROR_SYNTAX => 'Syntax error',
  58. JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
  59. );
  60. $error = json_last_error();
  61. return isset($ERRORS[$error]) ? $ERRORS[$error] : 'Unknown error';
  62. }
  63. }
  64. }
  65. catch (Exception $e) {
  66. echo 'Caught exception: ', $e->getMessage(), "\n";
  67. }
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment