Solved

JSON Encoding problem breaks calendar

Posted on 2013-12-03
13
542 Views
Last Modified: 2013-12-23
I have a calendar ('Fullcalendar'), which displays the reservations in our B&B. Suddenly the reservations in july and september are not displayed anymore (They are still in the db of Drupal)
My log gives two relevant messages:
         (1)Notice: Trying to get property of non-object in BookingEvent->formatJson() (line230 van /storage/web/public/sites/www.slapeninyerseke.nl/sites/all/modules/rooms/modules/rooms_availability/includes/rooms_availability.booking_event.inc).
        (2)Warning: json_encode(): Invalid UTF-8 sequence in argument in drupal_json_encode() (regel 4997 van /storage/web/public/sites/www.slapeninyerseke.nl/includes/common.inc).

From what I find on the net this has to do with the fact(???) that Mysql uses utf-8, but that my calendar data stream is apparently different. My log displays the data as a text file as they are supposed to appear in the calendar, but I cannot find any strange characters there. See for yourself:

[{"id":"1","start":"2013-07-01T13:00:00Z","end":"2013-07-03T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"},{"id":"-154","start":"2013-07-04T13:00:00Z","end":"2013-07-04T13:00:00Z","title":"Franci...","color":"#4F1800"},{"id":"1","start":"2013-07-05T13:00:00Z","end":"2013-07-05T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"},{"id":"-149","start":"2013-07-06T13:00:00Z","end":"2013-07-06T13:00:00Z","title":"Willy ...","color":"#4F1800"},{"id":"1","start":"2013-07-07T13:00:00Z","end":"2013-07-07T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"},{"id":"-157","start":"2013-07-08T13:00:00Z","end":"2013-07-08T13:00:00Z","title":"G.Char...","color":"#4F1800"},{"id":"1","start":"2013-07-09T13:00:00Z","end":"2013-07-09T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"},{"id":"-156","start":"2013-07-10T13:00:00Z","end":"2013-07-10T13:00:00Z","title":"Vander...","color":"#4F1800"},{"id":"1","start":"2013-07-11T13:00:00Z","end":"2013-07-14T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"},{"id":"-160","start":"2013-07-15T13:00:00Z","end":"2013-07-17T13:00:00Z","title":"Mw. Fiers","color":"#4F1800"},{"id":"1","start":"2013-07-18T13:00:00Z","end":"2013-07-18T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"},{"id":"-167","start":"2013-07-19T13:00:00Z","end":"2013-07-20T13:00:00Z","title":"Meeus","color":"#4F1800"},{"id":"1","start":"2013-07-21T13:00:00Z","end":"2013-07-22T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"},{"id":"-172","start":"2013-07-23T13:00:00Z","end":"2013-07-23T13:00:00Z","title":"Onbeke...","color":"#4F1800"},{"id":"1","start":"2013-07-24T13:00:00Z","end":"2013-07-25T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"},{"id":"-145","start":"2013-07-26T13:00:00Z","end":"2013-07-26T13:00:00Z","title":"H.J. M...","color":"#4F1800"},{"id":"-176","start":"2013-07-27T13:00:00Z","end":"2013-07-27T13:00:00Z","title":null,"color":"#4F1800"},{"id":"1","start":"2013-07-28T13:00:00Z","end":"2013-07-31T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"}]

Open in new window


It appears I need to do some conversion from or to UTF, but I have no idea. Please help.

Thanks

Theo Richel
0
Comment
Question by:TheoRichel
  • 7
  • 6
13 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39693705
You may want to start by understanding character encoding.  This article should help.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11880-Unicode-PHP-and-Character-Collisions.html

In the instant case, the data being fed to JSON_encode is not valid UTF-8.  You would want to find out where this data comes from.  The Notice about "Trying to get property of non-object" is almost certainly an artifact of an encoding or decoding error.
0
 

Author Comment

by:TheoRichel
ID: 39693752
Allright Ill read that piece. Thanks
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39693977
Also, check the notes here.  You may be able to get JSON to tell you what's wrong.  in my experience the error messages were not particularly useful, but a little bit better than nothing.
http://php.net/manual/en/function.json-last-error.php
0
 

Author Comment

by:TheoRichel
ID: 39694226
Thanks very much. I'll get back.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39694252
We'll be here and will do our best to help!
0
 

Author Comment

by:TheoRichel
ID: 39695258
I have read your piece and find it very informative, though I wouldnt know how to execute the scripts you provide. I have also tried to install a Drupal module ('Php-error') which is supposed to tell me where the problem is, but I should install the PHP-error library for that and according to the readme only an idiot does that on a production site. As I am not an idiot and this is a production site, I havent progressed much.

I can see the datastream that the calendar apparently refuses, but I wouldnt know how to make the datastream that is accepted (the months that display well) visible. Then I could compare.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39695334
You might consider using PHP error_log() to record the data.  I believe you can also set error_reporting() and log_errors separately, so you can see the errors in the logs.

I'll add this to the Drupal Zone, too.
0
 

Author Comment

by:TheoRichel
ID: 39695375
Thanks
PHPInfo tells me that there is no error log specified and my host does not allow me access to the PHP.ini. (I guess I chose the wrong host).
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39703089
Tell your host to set up error_log.  It's not optional -- you cannot work without it.  It would be like Schroedinger trying to be a veterinarian.  You must be able to get quick and accurate visualization of error messages.

Who is the host?  I'd like to add them to my list of "do not disturb" entities.
0
 

Author Comment

by:TheoRichel
ID: 39716128
The host is mijndomein.nl . I contacted them about this and will let you know.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39716600
While you're waiting to hear back from them, you might want to post a question here and ask about the high-quality hosting services that would be available in your country.  Or contact this fellow and ask what hosts he would recommend.
http://www.dragonbe.com/
0
 

Author Comment

by:TheoRichel
ID: 39735989
I will and will migrate to another host, but this is going to take some time and I do not know whether this problem will popup there as well, so I'll close this question.Many thanks sofar.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39736014
Thanks for the points and best of luck with it, ~Ray
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now