This is a migrated thread and some comments may be shown as answers.

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

3 Answers 199 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Ollie
Top achievements
Rank 1
Iron
Ollie asked on 29 Jun 2017, 09:44 PM

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;
        }
    }
});

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 03 Jul 2017, 08:28 AM
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 (charts) and form elements.
0
Ollie
Top achievements
Rank 1
Iron
answered on 04 Jul 2017, 03:20 PM

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" }]}

 

0
Stefan
Telerik team
answered on 06 Jul 2017, 06:25 AM
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 (charts) and form elements.
Tags
Data Source
Asked by
Ollie
Top achievements
Rank 1
Iron
Answers by
Stefan
Telerik team
Ollie
Top achievements
Rank 1
Iron
Share this question
or