Unicode quotes ( “ and ’ ) in the JSON data is not loading the kendo template

4 posts, 0 answers
  1. Ollie
    Ollie avatar
    8 posts
    Member since:
    Oct 2016

    Posted 29 Jun Link to this post

    Good day.

    We have a commenting system in our site and we're using a kendo template to display the comments. As the title stated, one comment that being returned from the database has those quotes and its preventing the whole template to be loaded, once we changed the quotes into the regular ones ( " and ' ), it loaded properly.

    I thought it's weird that it will not be handled. Any ideas or suggestions?

     

    var ds = new kendo.data.DataSource({
        transport: {
            read: {
               url: "/path/to/our/remote/function",
               type: "get",
                dataType: "json",
                cache: false,
                data: {
                    ID: id
                }
            }          
        },
        schema : {
            type: "json",
            data: "Comments",
            model: {   
                fields: {
                    Text: { field: "Text", type: "string" }     //need this for comments consisting of only a number
                }  
            },
            parse: function (data) {
                //additional processing
                var comments = data.Comments;  
                 
                $.map(comments, function (item, index) {
                    if (typeof(item.Created) !== "undefined" && item.Created != null) {
                        var current_datetime = moment();       
                        var created = moment(new Date(item.Created));          
                        item.Created = created.from(current_datetime);
                    }
                });            
                return data;
            }
        }
    });
  2. Stefan
    Admin
    Stefan avatar
    1131 posts

    Posted 03 Jul Link to this post

    Hello Ollie,

    I was not able to reproduce the same issue on my end.

    Could you please provide the JSON which is causing the issue, so we can investigate it further?

    Also, I noticed that the parse function is used as well and I can suggest checking the value of the field and if it is containing the Unicode quotes, to manually replace them and parse the valid JSON values.

    Another option will be to use a function to replace the string:

    http://dojo.telerik.com/uROPo


    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Ollie
    Ollie avatar
    8 posts
    Member since:
    Oct 2016

    Posted 04 Jul in reply to Stefan Link to this post

    Sample JSON:

    {"Comments": [{"CommentID": 348, "Created": "4 days ago", "Editable": 1, "Photo": "", "Poster": "Ollie", "Text": "“It happens when there is a problem with certain nerve cells in the brain which make an important chemical called dopamine. Dopamine sends signals to the part of your brain that controls movement.” Faces of Parkinson’s" }]}

     

  4. Stefan
    Admin
    Stefan avatar
    1131 posts

    Posted 06 Jul Link to this post

    Hello Ollie,

    Thank you for providing the JSON file.

    Still, after I used it in a template, the templates was rendered as expected:

    http://dojo.telerik.com/uROPo/3

    Please advise if I missed an important detail.

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top