Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5970185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:20:18+00:00 2026-05-22T20:20:18+00:00

I have a symfony app that uses the json_encode and json_decode to keep a

  • 0

I have a symfony app that uses the json_encode and json_decode to keep a record of some prices.
The problem is that json_decode works OK in one file (I can decode the string stored in my PSQL database), but when I call it from other file json_decode returns null, I’ve check the file encodings (all are utf-8) the tables and database encoding(utf-8 too). So I don’t know where the problem can be, tried utf8_encode() too…

Any help will be appreciated.
Thanks.

Here’s the valid encoded json (It was an array encoded by php json_encode)

{"1":{"1":{"fechaInicio":"30-05-2011","precios":{"1":{"precio":"20000","abreviatura":"CLP"}},"fechaRetiro":"31-05-2011"}},"2":{"2":{"fechaInicio":"30-05-2011","precios":{"1":{"precio":"20000","abreviatura":"CLP"}},"fechaRetiro":"31-05-2011"}}}

The array:

$preciosOfertor = Array ( [unidades] => Array ( [1] => Array ( [1] => Array ( [fechaInicio] => 30-05-2011 [precios] => Array ( [1] => Array ( [precio] => 20000 [abreviatura] => CLP ) ) [fechaRetiro] => 31-05-2011 ) ) [2] => Array ( [2] => Array ( [fechaInicio] => 30-05-2011 [precios] => Array ( [1] => Array ( [precio] => 20000 [abreviatura] => CLP ) ) [fechaRetiro] => 31-05-2011 ) ) ) ) 

To encode it I use:

$preciosOfertor = json_encode($preciosOfertor); 

Then I call

$precios = json_decode($databaseObject->getPreciosOfertor(),true); 

When i use json_decode in the file that encodes the array it works, but then when I use it in other file of the project I just get NULL with var_dump().

Installed Services_JSON as suggested, but now I’m getting an empty array

The encoded json with Services_JSON is this one:

{"unidades":{"1":{"1":{"fechaInicio":"30-05-2011","precios":{"1":{"precio":"20000","abreviatura":"CLP"}},"fechaRetiro":"31-05-2011"}}}}

But when I call $json->decode() I get Array ( )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:20:19+00:00Added an answer on May 22, 2026 at 8:20 pm

    Ok people, first thank you all for the help.

    I got the solution and It was all thanks to Zend Json library.

    Symfony uses escaping strategies to prevent XSS attacks, SQL Injection attacks, etc. So what happened here in my case, when I called json_encode and json_decode it was inside the object that Doctrine generates to represent my object (In this case a reservation), so because it was a local call to the row data (valoresOfertor), the data from the database was not escaped thus the methods worked fine.

    But then, when I tried to encode and decode the values of the row outside the reservation class, Symfony used it’s escaping strategy so

    "
    

    became

    &quot
    

    So, trying different JSON libraries, I used Zend one, and saw the exception that displayed (Syntax Error:

        at Zend_Json::decode('{"unidades":{"1":{"1":{"fechaInicio":"30-05-2011","precios":{"1":{"precio":"20000","abreviatura":"CLP"}},"fechaRetiro":"31-05-2011"}},"2":{"2":{"fechaInicio":"30-05-2011","precios":{"1":{"precio":"20000","abreviatura":"CLP"}},"fechaRetiro":"31-05-2011"}}}}')
    in SF_ROOT_DIR/apps/saas/modules/editreserva/templates/habitacionesSuccess.php line 20 ...
    

    So then i Added the following line:

    htmlspecialchars_decode($jsonVariable);
    

    And it worked.

    I hope it helps someone if he experiments the same with symfony and json.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have FireSymfony that allows one to view the Symfony, PHP variables in a
I have a Symfony app that populates the widgets of a portal application and
I have a project that I wrote in PHP/symfony that uses 45 tables. I'm
I have an app that I'm porting from PHP/symfony to Ruby/Rails. Though the language
In my Symfony/Doctrine app, I have a query that orders by RANDOM(). I call
I have a Symfony application that uses Doctrine as its ORM. Based on Symfony's
I have done a svn co for a repository that contains a symfony app.
I have an application that I'm converting to Symfony/Doctrine. It currently stores a serialized
I am using Symfony 1.4 to build a web app that allows photo sharing.
I have a developed a small web-app in Symfony 2 and Doctrine 2. Can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.