[Solved] JSON Parse Error [Syntax Error]

Moderator: c0rdawg

[Solved] JSON Parse Error [Syntax Error]

Postby alaoa » Sat Feb 28, 2009 11:59 pm

I spent hours on this and I feel like kicking my self. I'm just posing this for others who run into this issue. If your are getting this error

Code: Select all
Open Flash Chart

JSON Parse Error [Syntax Error]
Error at character 0, line 1:

0: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://


then your not encoding the url.

if your using php make sure you call the urlencode() function for the "data-file" var.
Last edited by c0rdawg on Sat Oct 17, 2009 5:57 pm, edited 1 time in total.
Reason: Solved
alaoa
 
Posts: 2
Joined: Sat Feb 28, 2009 11:55 pm

Re: JSON Parse Error [Syntax Error]

Postby emclaughlin » Mon Mar 02, 2009 8:56 pm

I second that. This should be added to the Tutorial:

Here's code that works:

Code: Select all
<?php
$startDate = '2009/2/20';
$clientID = '1005';

$daturl = urlencode("/report/all_conversions.php?date=".$startDate."&clientid=".$clientID);
?>

<script type="text/javascript" src="/report/ofc/js/swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF(
  "/report/ofc/open-flash-chart.swf", "all_conversions_report", "950", "150",
  "9.0.0", "expressInstall.swf",
  {"data-file":"<?php echo $daturl; ?>"}
  );
</script>

<div id="all_conversions_report"></div>
emclaughlin
 
Posts: 3
Joined: Fri Feb 27, 2009 8:04 pm

Re: JSON Parse Error [Syntax Error]

Postby shrinerp » Wed Mar 04, 2009 3:54 pm

I am encoding the URL and still getting that error in IE, at least I think it is that error, but everything works just fine in FF. I am Stumped!!! and would love some help

The charts work just fine in Firefox.

This is my JSON string as rendered by Firebug in Firefox on an AJAX call

Code: Select all
{
  "elements": [
    {
      "type": "bar",
      "values": [
        37,
        23,
        23,
        22,
        22,
        20,
        18,
        18,
        18,
        16,
        16,
        16,
        15,
        15,
        14,
        14,
        14,
        13,
        13,
        13,
        13,
        13,
        12,
        12,
        12,
        11,
        11,
        11,
        10,
        10
      ],
      "colour": "#CC3366"
    }
  ],
  "title": {
    "text": "Facebook status messages by User\/Week"
  },
  "x_axis": {
    "labels": {
      "rotate": "vertical",
      "colour": "#000000",
      "size": 10,
      "labels": [
        "Rod Rodillon",
        "Jim Jacobson",
        "Tracy Bille-Newkirk",
        "John Nowicki",
        "Matt Krachunis",
        "Gus Peterson",
        "Skip Cadorette",
        "Jeff Keuss",
        "Nathan Solla",
        "Rachel Vestnys Gloger",
        "Brian Snyder",
        "Ryan Pritchett",
        "Cheryle Myers",
        "Mark Austria",
        "John Mitchell",
        "Michael Medoro",
        "Rebekah Logue",
        "Mason Rutledge",
        "Jennifer Tracer",
        "Cliff Gilley",
        "Andy Anderson",
        "Jennifer Esterly Waldroup",
        "Jeff Huber",
        "Lewis Van Tassel",
        "Lacey Wahl",
        "Heidi Nelson",
        "Laura Breen-Young",
        "Heidi Clum",
        "Margie Gallagher",
        "Ashley Brown"
      ]
    }
  },
  "y_axis": {
    "min": 0,
    "max": 39,
    "steps": 2
  }
}
shrinerp
 
Posts: 3
Joined: Wed Mar 04, 2009 6:45 am

Re: JSON Parse Error [Syntax Error]

Postby dz_ » Sun Mar 08, 2009 1:38 pm

The JSON looks good. Can you post the code which loads the chart?
dz_
OFC Genius
 
Posts: 591
Joined: Tue Sep 09, 2008 12:56 am

Re: JSON Parse Error [Syntax Error]

Postby encus » Wed Mar 11, 2009 7:21 am

I wonder why my server work fine for IE7 without using the urlencode() php function.. it seem to me very strange...
encus
 
Posts: 3
Joined: Thu Mar 05, 2009 4:43 am

Re: JSON Parse Error [Syntax Error]

Postby shrinerp » Sun Mar 15, 2009 8:06 pm

OK, so I have spent more time debuggin this!

Things work fine for me with this in IE, but when I wrap this wihtin an iframe as an application in Facebook I get an intermitten JSON error that I listed above.

Now if I load app as a Facebook Connect app first, then the SWF loads just fine within FB

If I load FB first, I get the Javascript/JSON error.
shrinerp
 
Posts: 3
Joined: Wed Mar 04, 2009 6:45 am

Re: JSON Parse Error [Syntax Error]

Postby c0rdawg » Sun Mar 15, 2009 11:16 pm

Sounds like cross-site scripting prevention... I think there was some information on the forums about setting flash so you can do that...
c0rdawg
 
Posts: 189
Joined: Tue Sep 23, 2008 2:00 am

Re: JSON Parse Error [Syntax Error]

Postby shrinerp » Tue Mar 17, 2009 9:16 pm

It is possible, it works with FF, which is the weird thing and it works intermittently with MSIE...

I will keep digging, sounds like there isn't an easy answer

paul
shrinerp
 
Posts: 3
Joined: Wed Mar 04, 2009 6:45 am

Re: JSON Parse Error [Syntax Error]

Postby jstarace » Sun Mar 29, 2009 7:57 am

Now, I'm aware that my issue probably is that I'm not urlencoding it properly. The thing is I have no clue how to do it properly. On my page I don't receive an error message, but the video doesn't load. The JSON looks to be pulling all the data correctly, I've tried to follow any steps I could find but am frankly,... lost.

When I leave it like this;

<head>

<script type="text/javascript" src="/derek/js/swfobject.js"></script>
<script type="text/javascript">

swfobject.embedSWF(
"/home/jstarace/zardozthegreat.com/open-flash-chart.swf", "handletime",
"400", "300", "9.0.0", "expressInstall.swf",
{"data-file":"/derek/derekmetrics.php"} );

swfobject.embedSWF(
"/Users/derek/open-flash-chart.swf", "sales",
"400", "300", "9.0.0", "expressInstall.swf",
{"data-file":"/derek/dereksales.php"} );

swfobject.embedSWF(
"/Users/derek/open-flash-chart.swf", "csat",
"400", "300", "9.0.0", "expressInstall.swf",
{"data-file":"/derek/derekcsat.php"} );

</script>
</head>

Nothing loads - but there's also no error messages

But if I change it to;

<?php

$daturl = urlencode("/derek/derek.php);
?>

<head>

<script type="text/javascript" src="/derek/js/swfobject.js"></script>
<script type="text/javascript">

swfobject.embedSWF(
"/home/jstarace/zardozthegreat.com/open-flash-chart.swf", "handletime",
"400", "300", "9.0.0", "expressInstall.swf",
{"data-file":"<?php echo ?daturl; ?>"} );

swfobject.embedSWF(
"/Users/derek/open-flash-chart.swf", "sales",
"400", "300", "9.0.0", "expressInstall.swf",
{"data-file":"/derek/dereksales.php"} );

swfobject.embedSWF(
"/Users/derek/open-flash-chart.swf", "csat",
"400", "300", "9.0.0", "expressInstall.swf",
{"data-file":"/derek/derekcsat.php"} );


</script>
</head>

I get

Parse error: syntax error, unexpected T_STRING in /home/jstarace/zardozthegreat.com/derek/derek.php on line 8

Who knows it may just be that this is my first 12 hour stint working on a site and I can't think. But if you could please help that would be fantastic. Oh yeah and assume I know nothing... cause I don't :D
Attachments
Picture 1.png
that's what I see on the page
Picture 1.png (14.33 KiB) Viewed 4148 times
jstarace
 
Posts: 1
Joined: Sun Mar 29, 2009 7:42 am

Re: JSON Parse Error [Syntax Error]

Postby c0rdawg » Sun Mar 29, 2009 2:35 pm

derek.php has an error on line 7 or 8. You're probably missing a semicolon or something...
c0rdawg
 
Posts: 189
Joined: Tue Sep 23, 2008 2:00 am

Next

Return to PHP

Who is online

Users browsing this forum: No registered users and 1 guest