简体   繁体   中英

Symfony2 JMS Serializer JSON_ constant error

PHP Fatal error: Uncaught exception 'JMS\\Serializer\\Exception\\InvalidArgumentException' with message 'Expected either an integer representing one of the JSON_ constants, or a string of the constant itself.' in /var/www/mobilegolfplan.com/vendor/jms/serializer-bundle/JMS/SerializerBundle/DependencyInjection/Configuration.php:142\\nStack trace:\\n#0 [internal function]: JMS\\SerializerBundle\\DependencyInjection\\{closure}(Array)\\n#1 /var/www/mobilegolfplan.com/vendor/symfony/symfony/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php(229): call_user_func(Object(Closure), Array)\\n#2 /var/www/mobilegolfplan.com/vendor/symfony/symfony/src/Symfony/Component/Config/Definition/BaseNode.php(254): Symfony\\Component\\Config\\Definition\\Builder\\{closure}(Array)\\n#3 /var/www/mobilegolfplan.com/vendor/symfony/symfony/src/Symfony/Component/Config/Definition/ArrayNode.php(308): Symfony\\Component\\Config\\Definition\\BaseNode->normalize(Array)\\n#4 /var/www/mobilegolfplan.com/vendor/symfony/symfony/src/Symfony/Component/Config/Definition/BaseNode in /var/www/mobilegolfplan.com/vendor/jms/serializer-bundle/JMS/SerializerBundle/DependencyInjection/Configuration.php on line 142

I tried install a project in production server and i got error. PHP json extension installed and enabled. If i want try composer install, i was seeing that error , again, again and again.

How i fix this problem ?

In the JSON Constants in the config file try to give 0 like this:

jms_serializer:
    visitors:
        json:
            options: 0

You might not be using the correct version of PHP. Are you using PHP 5.3 or less?

For the Json constants: JSON_UNESCAPED_SLASHES , JSON_UNESCAPED_UNICODE to work, you must use PHP 5.4 or higher.

In PHP 5.4 or more the below code will work:

jms_serializer:
    visitors:
        json:
            options:   [ JSON_UNESCAPED_SLASHES , JSON_UNESCAPED_UNICODE ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM