Solved

JSON Encoding problem breaks calendar

Posted on 2013-12-03
13
536 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

747 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

12 Experts available now in Live!

Get 1:1 Help Now