2

I installed the JMSSerializerbundle with symfony2 to get JSON response of my Doctrine Entities.

The problem is that when I have a string field created by ckeditor and content HTML tags I got an invalid JSON response.

    "courses": [
    {
        "requests": [

        ],
        "id": 38,
        "course_content": "
            pmlllo<\/p>",
        "course_title": "hhjhhhh",
        "course_type": {
            "id": 3,
            "name": "Dershane Dersi",
            "courses": [

            ]
        },
        "description": "

             ppoookokokok<\/p>"
    }
 ]

Using http://jsonlint.com/ I got this error

Parse error on line 154:...
"course_content": "pmlllo</p>",
-----------------------^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

Hamza MHIRA
  • 157
  • 1
  • 11

1 Answers1

2

You got to encode HTML if you want to store it in JSON. On the server-side (PHP), htmlentities should do the trick. For the client side, please refer to this question: Escaping HTML strings with jQuery.

Community
  • 1
  • 1
oleq
  • 15,697
  • 1
  • 38
  • 65