-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output JSON and Specialchars #289
Comments
use PHP 5.4+ and the JSON_UNESCAPED_SLASHES flag for json_encode |
note that it will be configured this way: jms_serializer:
visitors:
json:
options: JSON_UNESCAPED_SLASHES |
Well, you probably also want jms_serializer:
visitors:
json:
options: [JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE] |
Oh dude! Thats sweet, I was hoping there is a thing like that. Case Closed :) 👍 |
you should push the "close" button then (I cannot do it as I'm not the maintainer of the bundle and not the creator of the issue) |
@stof #289 (comment) What if this doesn't work? I setted it up in my config.yml but that doesn't seem to change the output which is still quote-escaped |
I can confirm that. Same Here. Some more information about my setup:
|
Can you share your configurations ?
…On 27 Jun 2017 14:02, "Sven" ***@***.***> wrote:
I setted it up in my config.yml but that doesn't seem to change the output
which is still quote-escaped
I can confirm that. Same Here. Some more information about my setup:
- symfony/symfony v. 3.3.2
- jms/serializer-bundle v. 2.0.0
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#289 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAvaJwGLacCekJVCY9-Tjpn6FvIt0Kqlks5sIO9CgaJpZM4Alot7>
.
|
Sure. It's the same as described before. Location: config.yml jms_serializer:
visitors:
json:
options: [JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE] |
hmm, i tried and it works... are you sure is not an encoding issue? can you create a failing test case? |
Is there any possibility to set this on a per-use basis? I could not find a way to set this on the |
@buffcode , @alexandr-lakeev , there is, but it's dirty one. Look: /** @var Symfony\Component\DependencyInjection\Container $container */
$serializer = $container->get('jms_serializer');
/** @var Product $product An object for serialization */
$product = (new Product(123, "Nature's Table"))->setBrand('5" pack');
$jsonSerializationVisitor = $container->get('jms_serializer.json_serialization_visitor');
//Save options.
$oldOptions = $jsonSerializationVisitor->getOptions();
//Set options you want now.
$jsonSerializationVisitor->setOptions(JSON_HEX_APOS);
echo $serializer->serialize($product, 'json') . PHP_EOL;
//Restore old options.
$jsonSerializationVisitor->setOptions($oldOptions);
echo $serializer->serialize($product, 'json'); Output:
|
Hello there!
I recently posted a problem for the restbundle (FriendsOfSymfony/FOSRestBundle#438).
Long story short I dont want my special chars to be "escaped" or anything else.
Like for example the string:
{"wikipedia":"en.wikipedia.org/wiki/Mexico_City"}
would be in my situation:
{"wikipedia":"en.wikipedia.org/wiki/Mexico_City"}
I know that this is perfectly valid, but the output should stay like the first string.
Can anyone help?
The text was updated successfully, but these errors were encountered: