Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
jsonconverter.php
1<?
9
13
14Loc::loadMessages(__FILE__);
15
16class JsonConverter implements IConverter
17{
24 public static function isValid($string)
25 {
26 $string = trim($string);
27 $char = mb_substr($string, 0, 1);
28 if(!in_array($char, array('{', '[')))
29 {
30 return false;
31 }
32 $char = mb_substr($string, -1);
33 if(!in_array($char, array('}', ']')))
34 {
35 return false;
36 }
37
38 try
39 {
40 $r = Json::decode($string);
41 return is_array($r);
42 }
43 catch (ArgumentException $exception)
44 {
45 return false;
46 }
47 }
48
55 public static function toArray($string)
56 {
57 $blockContent = new BlockContent();
58 try
59 {
60 $list = Json::decode($string);
61 if (!is_array($list))
62 {
63 return $blockContent;
64 }
65 }
66 catch (ArgumentException $exception)
67 {
68 return $blockContent;
69 }
70
71 foreach ($list as $item)
72 {
73 $type = trim($item['type']);
74 $place = trim($item['place']);
75 $value = trim($item['value']);
76 $blockContent->add($type, $place, $value);
77 }
78
79 return $blockContent;
80 }
81}
static loadMessages($file)
Definition loc.php:64