[Proto-Scripty] Re: HTML breaks JSON

2009-06-08 Thread Matt Foster

You guys are crazy...you send json_encode an object, not a string!!

http://us3.php.net/manual/en/function.json-encode.php

--

http://positionabsolute.net


On Jun 5, 6:16 am, Alex McAuley webmas...@thecarmarketplace.com
wrote:
 very strange .. works for me with anything all the time

 - Original Message -
 From: Matt guitarroman...@gmail.com
 To: Prototype  script.aculo.us prototype-scriptaculous@googlegroups.com
 Sent: Friday, June 05, 2009 10:05 AM
 Subject: [Proto-Scripty] Re: HTML breaks JSON

 Hi Alex,

 Still didn't work for me :( Just produced broken HTML output again.

 On Jun 4, 5:24 pm, Alex McAuley webmas...@thecarmarketplace.com
 wrote:
  You need to do it a bit differently with php json_encode/decode ... i had
  this problem when i first started using it

  where you send post data (JSON) as p

  $post=str_replace('\', '', $_POST['p']);
  $json=$post;
  $d=json_decode($json,true);

  foreach($d as $key=$val) { .. do what you will with it after this
  unless you know the key names !!

  This should do the trick for you

  HTH

  ALex

  - Original Message -
  From: Matt i...@leedsguide.co.uk
  To: Prototype  script.aculo.us
  prototype-scriptaculous@googlegroups.com
  Sent: Thursday, June 04, 2009 4:30 PM
  Subject: [Proto-Scripty] Re: HTML breaks JSON

  Hi again,

  I've been running addslashes() on the input before running json_encode
  () and it still creates problems when I pass it through AJAX - breaks
  HTML tags etc. If I turn addslashes() off, any occurence of  in the
  body text (eg quotes from speakers etc) breaks the code again. Does
  anyone have a foolproof method?

  Cheers
  Matt

  On Apr 24, 9:54 pm, Matt Foster mattfoste...@gmail.com wrote:
   What are you sending to PHP's json_encode? It is expecting a
   structure to serialize into a JSON syntax string.

   $struct = array(message = h1Hello World/h1Who says we can't
   have any kind of \quotes\ we want?);

   echo json_encode($struct);

   If you try to run json_encode on your already JSONified string, yeah
   its going to cause problems...

   --

  http://positionabsolute.net

   On Apr 24, 12:26 pm, T.J. Crowder t...@crowdersoftware.com wrote:

@Ananth:

Converting to Base64 would be massive overkill, surely.

@OP:

There's no reason you can't include strings containing HTML in JSON
data. You just have to make sure your strings are valid string
literals, like this:

{
message: pThis is HTML./p

}

There's nothing special other than making sure the HTML is correctly
escaped -- e.g., if you're putting the JSON string in double quotes,
naturally any double quotes in the HTML will need a backslash in front
of them -- as, for that matter, will any backslashes!

HTH,
--
T.J. Crowder
tj / crowder software / com

On Apr 24, 5:05 pm, Ananth Raghuraman araghuram...@gmail.com wrote:

 JSON should not contain HTML for tactical/ease of programming
 purposes
 unless the HTML is there as part of a larger design, but there may
 or
 may
 not be implementation restrictions.
 If you are facing problems, can you try encoding the HTML string
 (Base64)
 and decoding back (using Javascript Base64 code ) before display on
 the
 browser?

 On Fri, Apr 24, 2009 at 11:30 AM, Matt guitarroman...@gmail.com
 wrote:

  Hi there,

  I'm using PHP to output some JSON through AJAX to my page. It
  breaks
  whenever I use a backslash or quote mark.

  I've tried using php's json_encode function which doesn't seem to
  help, just breaks it further. I've also tried php's addslashes()
  to
  the output, again, same problem.

  Am I approaching this correctly, fundamentally? Is JSON supposed
  to
  contain HTML?

  Thanks,

  Matt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-06-08 Thread Walter Lee Davis

Sorry, here's a clearer listing:

http://us3.php.net/manual/en/language.types.intro.php

Walter

On Jun 8, 2009, at 11:05 AM, Walter Lee Davis wrote:

 That means it can be an Array, an Object, a String, an Integer, a
 Boolean, a Floating Point Number or NULL, according to this list of
 Types:

 http://us3.php.net/manual/en/language.types.resource.php


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-06-08 Thread Richard Quadling

2009/6/8 Walter Lee Davis wa...@wdstudio.com:

 Sorry, here's a clearer listing:

 http://us3.php.net/manual/en/language.types.intro.php

 Walter

 On Jun 8, 2009, at 11:05 AM, Walter Lee Davis wrote:

 That means it can be an Array, an Object, a String, an Integer, a
 Boolean, a Floating Point Number or NULL, according to this list of
 Types:

 http://us3.php.net/manual/en/language.types.resource.php


 


Sending PHP's json_encode anything other than an array is pointless.

http://bugs.php.net/bug.php?id=38680

-- 
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
Standing on the shoulders of some very clever giants!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-06-05 Thread Matt

Hi Alex,

Still didn't work for me :( Just produced broken HTML output again.

On Jun 4, 5:24 pm, Alex McAuley webmas...@thecarmarketplace.com
wrote:
 You need to do it a bit differently with php json_encode/decode ... i had
 this problem when i first started using it

 where you send post data (JSON) as p

 $post=str_replace('\', '', $_POST['p']);
 $json=$post;
 $d=json_decode($json,true);

 foreach($d as $key=$val) { .. do what you will with it after this
 unless you know the key names !!

 This should do the trick for you

 HTH

 ALex

 - Original Message -
 From: Matt i...@leedsguide.co.uk
 To: Prototype  script.aculo.us prototype-scriptaculous@googlegroups.com
 Sent: Thursday, June 04, 2009 4:30 PM
 Subject: [Proto-Scripty] Re: HTML breaks JSON

 Hi again,

 I've been running addslashes() on the input before running json_encode
 () and it still creates problems when I pass it through AJAX - breaks
 HTML tags etc. If I turn addslashes() off, any occurence of  in the
 body text (eg quotes from speakers etc) breaks the code again. Does
 anyone have a foolproof method?

 Cheers
 Matt

 On Apr 24, 9:54 pm, Matt Foster mattfoste...@gmail.com wrote:
  What are you sending to PHP's json_encode? It is expecting a
  structure to serialize into a JSON syntax string.

  $struct = array(message = h1Hello World/h1Who says we can't
  have any kind of \quotes\ we want?);

  echo json_encode($struct);

  If you try to run json_encode on your already JSONified string, yeah
  its going to cause problems...

  --

 http://positionabsolute.net

  On Apr 24, 12:26 pm, T.J. Crowder t...@crowdersoftware.com wrote:

   @Ananth:

   Converting to Base64 would be massive overkill, surely.

   @OP:

   There's no reason you can't include strings containing HTML in JSON
   data. You just have to make sure your strings are valid string
   literals, like this:

   {
   message: pThis is HTML./p

   }

   There's nothing special other than making sure the HTML is correctly
   escaped -- e.g., if you're putting the JSON string in double quotes,
   naturally any double quotes in the HTML will need a backslash in front
   of them -- as, for that matter, will any backslashes!

   HTH,
   --
   T.J. Crowder
   tj / crowder software / com

   On Apr 24, 5:05 pm, Ananth Raghuraman araghuram...@gmail.com wrote:

JSON should not contain HTML for tactical/ease of programming purposes
unless the HTML is there as part of a larger design, but there may or
may
not be implementation restrictions.
If you are facing problems, can you try encoding the HTML string
(Base64)
and decoding back (using Javascript Base64 code ) before display on
the
browser?

On Fri, Apr 24, 2009 at 11:30 AM, Matt guitarroman...@gmail.com
wrote:

 Hi there,

 I'm using PHP to output some JSON through AJAX to my page. It breaks
 whenever I use a backslash or quote mark.

 I've tried using php's json_encode function which doesn't seem to
 help, just breaks it further. I've also tried php's addslashes() to
 the output, again, same problem.

 Am I approaching this correctly, fundamentally? Is JSON supposed to
 contain HTML?

 Thanks,

 Matt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-06-05 Thread Szymon Wilkołazki

Matt wrote:
 Hi Alex,
 
 Still didn't work for me :( Just produced broken HTML output again.
 

If your html code is not broken on inside of php variable, then it 
won't break anything inside json_encode;

[code]
?php
$html = '
 div id=someIdthis is correct html
 span id=\'singleQuote\'
 You have to escape single Quotes
 FOR PHP SAKE ONLY.
 If you get the HTML from file, or from
 database, then NO ESCAPING is needed.
 You need to escape quotes only for PHP
 parser, just as in any string.
 /span
 /div';
$json = json_encode($html);
echo $json;
?
[/code]
//produces:
\ndiv id=\someId\this is correct html\nspan 
id='singleQuote'\nYou have to escape single Quotes \n 
 FOR PHP SAKE ONLY. \nIf you get the HTML from 
file, or from \ndatabase, then NO ESCAPING is needed. \n 
   You need to escape quotes only for PHP \n 
parser, just as in any string.\n\/span\n\/div

Json_encode() function does EVERYTHING that is needed to escape the 
javascript strings, you do not need to have any kind of add_slashes().
In fact, add_slashes will break things, as the slashes will be escaped 
by json_encode() funciton, and they will be visible in html.


Take a look if you have not over-escaped the html. You might have 
magic-quotes enabled which automagicly adds slashes for you. This is 
evil option, as you have little control over what is happening.

Hope this helps

 On Jun 4, 5:24 pm, Alex McAuley webmas...@thecarmarketplace.com
 wrote:
 You need to do it a bit differently with php json_encode/decode ... i had
 this problem when i first started using it

 where you send post data (JSON) as p

 $post=str_replace('\', '', $_POST['p']);
 $json=$post;
 $d=json_decode($json,true);

 foreach($d as $key=$val) { .. do what you will with it after this
 unless you know the key names !!

I totally do not understand what you are doing here. Could you explain 
a little bit?



P.S. It is much easier to read posts if everyone would ansver below or 
inline of the previous post, not Top-Post. Just like T.J. Crowder did.

-- 
Best Regards,
SWilk


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-06-05 Thread Alex McAuley

very strange .. works for me with anything all the time
- Original Message - 
From: Matt guitarroman...@gmail.com
To: Prototype  script.aculo.us prototype-scriptaculous@googlegroups.com
Sent: Friday, June 05, 2009 10:05 AM
Subject: [Proto-Scripty] Re: HTML breaks JSON



Hi Alex,

Still didn't work for me :( Just produced broken HTML output again.

On Jun 4, 5:24 pm, Alex McAuley webmas...@thecarmarketplace.com
wrote:
 You need to do it a bit differently with php json_encode/decode ... i had
 this problem when i first started using it

 where you send post data (JSON) as p

 $post=str_replace('\', '', $_POST['p']);
 $json=$post;
 $d=json_decode($json,true);

 foreach($d as $key=$val) { .. do what you will with it after this
 unless you know the key names !!

 This should do the trick for you

 HTH

 ALex

 - Original Message -
 From: Matt i...@leedsguide.co.uk
 To: Prototype  script.aculo.us 
 prototype-scriptaculous@googlegroups.com
 Sent: Thursday, June 04, 2009 4:30 PM
 Subject: [Proto-Scripty] Re: HTML breaks JSON

 Hi again,

 I've been running addslashes() on the input before running json_encode
 () and it still creates problems when I pass it through AJAX - breaks
 HTML tags etc. If I turn addslashes() off, any occurence of  in the
 body text (eg quotes from speakers etc) breaks the code again. Does
 anyone have a foolproof method?

 Cheers
 Matt

 On Apr 24, 9:54 pm, Matt Foster mattfoste...@gmail.com wrote:
  What are you sending to PHP's json_encode? It is expecting a
  structure to serialize into a JSON syntax string.

  $struct = array(message = h1Hello World/h1Who says we can't
  have any kind of \quotes\ we want?);

  echo json_encode($struct);

  If you try to run json_encode on your already JSONified string, yeah
  its going to cause problems...

  --

 http://positionabsolute.net

  On Apr 24, 12:26 pm, T.J. Crowder t...@crowdersoftware.com wrote:

   @Ananth:

   Converting to Base64 would be massive overkill, surely.

   @OP:

   There's no reason you can't include strings containing HTML in JSON
   data. You just have to make sure your strings are valid string
   literals, like this:

   {
   message: pThis is HTML./p

   }

   There's nothing special other than making sure the HTML is correctly
   escaped -- e.g., if you're putting the JSON string in double quotes,
   naturally any double quotes in the HTML will need a backslash in front
   of them -- as, for that matter, will any backslashes!

   HTH,
   --
   T.J. Crowder
   tj / crowder software / com

   On Apr 24, 5:05 pm, Ananth Raghuraman araghuram...@gmail.com wrote:

JSON should not contain HTML for tactical/ease of programming 
purposes
unless the HTML is there as part of a larger design, but there may 
or
may
not be implementation restrictions.
If you are facing problems, can you try encoding the HTML string
(Base64)
and decoding back (using Javascript Base64 code ) before display on
the
browser?

On Fri, Apr 24, 2009 at 11:30 AM, Matt guitarroman...@gmail.com
wrote:

 Hi there,

 I'm using PHP to output some JSON through AJAX to my page. It 
 breaks
 whenever I use a backslash or quote mark.

 I've tried using php's json_encode function which doesn't seem to
 help, just breaks it further. I've also tried php's addslashes() 
 to
 the output, again, same problem.

 Am I approaching this correctly, fundamentally? Is JSON supposed 
 to
 contain HTML?

 Thanks,

 Matt



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-06-04 Thread Matt

Hi again,

I've been running addslashes() on the input before running json_encode
() and it still creates problems when I pass it through AJAX - breaks
HTML tags etc. If I turn addslashes() off, any occurence of  in the
body text (eg quotes from speakers etc) breaks the code again. Does
anyone have a foolproof method?

Cheers
Matt


On Apr 24, 9:54 pm, Matt Foster mattfoste...@gmail.com wrote:
 What are you sending to PHP's json_encode?  It is expecting a
 structure to serialize into a JSON syntax string.

 $struct = array(message = h1Hello World/h1Who says we can't
 have any kind of \quotes\ we want?);

 echo json_encode($struct);

 If you try to run json_encode on your already JSONified string, yeah
 its going to cause problems...

 --

 http://positionabsolute.net

 On Apr 24, 12:26 pm, T.J. Crowder t...@crowdersoftware.com wrote:

  @Ananth:

  Converting to Base64 would be massive overkill, surely.

  @OP:

  There's no reason you can't include strings containing HTML in JSON
  data.  You just have to make sure your strings are valid string
  literals, like this:

  {
      message: pThis is HTML./p

  }

  There's nothing special other than making sure the HTML is correctly
  escaped -- e.g., if you're putting the JSON string in double quotes,
  naturally any double quotes in the HTML will need a backslash in front
  of them -- as, for that matter, will any backslashes!

  HTH,
  --
  T.J. Crowder
  tj / crowder software / com

  On Apr 24, 5:05 pm, Ananth Raghuraman araghuram...@gmail.com wrote:

   JSON should not contain HTML for tactical/ease of programming purposes
   unless the HTML is there as part of a larger design, but there may or may
   not be implementation restrictions.
   If you are facing problems, can you try encoding the HTML string (Base64)
   and decoding back (using Javascript Base64 code ) before display on the
   browser?

   On Fri, Apr 24, 2009 at 11:30 AM, Matt guitarroman...@gmail.com wrote:

Hi there,

I'm using PHP to output some JSON through AJAX to my page. It breaks
whenever I use a backslash or quote mark.

I've tried using php's json_encode function which doesn't seem to
help, just breaks it further. I've also tried php's addslashes() to
the output, again, same problem.

Am I approaching this correctly, fundamentally? Is JSON supposed to
contain HTML?

Thanks,

Matt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-06-04 Thread Alex McAuley

You need to do it a bit differently with php json_encode/decode ... i had 
this problem when i first started using it

where you send post data (JSON) as p


$post=str_replace('\', '', $_POST['p']);
$json=$post;
$d=json_decode($json,true);

foreach($d as $key=$val) { .. do what you will with it after this 
unless you know the key names !!


This should do the trick for you

HTH

ALex
- Original Message - 
From: Matt i...@leedsguide.co.uk
To: Prototype  script.aculo.us prototype-scriptaculous@googlegroups.com
Sent: Thursday, June 04, 2009 4:30 PM
Subject: [Proto-Scripty] Re: HTML breaks JSON



Hi again,

I've been running addslashes() on the input before running json_encode
() and it still creates problems when I pass it through AJAX - breaks
HTML tags etc. If I turn addslashes() off, any occurence of  in the
body text (eg quotes from speakers etc) breaks the code again. Does
anyone have a foolproof method?

Cheers
Matt


On Apr 24, 9:54 pm, Matt Foster mattfoste...@gmail.com wrote:
 What are you sending to PHP's json_encode? It is expecting a
 structure to serialize into a JSON syntax string.

 $struct = array(message = h1Hello World/h1Who says we can't
 have any kind of \quotes\ we want?);

 echo json_encode($struct);

 If you try to run json_encode on your already JSONified string, yeah
 its going to cause problems...

 --

 http://positionabsolute.net

 On Apr 24, 12:26 pm, T.J. Crowder t...@crowdersoftware.com wrote:

  @Ananth:

  Converting to Base64 would be massive overkill, surely.

  @OP:

  There's no reason you can't include strings containing HTML in JSON
  data. You just have to make sure your strings are valid string
  literals, like this:

  {
  message: pThis is HTML./p

  }

  There's nothing special other than making sure the HTML is correctly
  escaped -- e.g., if you're putting the JSON string in double quotes,
  naturally any double quotes in the HTML will need a backslash in front
  of them -- as, for that matter, will any backslashes!

  HTH,
  --
  T.J. Crowder
  tj / crowder software / com

  On Apr 24, 5:05 pm, Ananth Raghuraman araghuram...@gmail.com wrote:

   JSON should not contain HTML for tactical/ease of programming purposes
   unless the HTML is there as part of a larger design, but there may or 
   may
   not be implementation restrictions.
   If you are facing problems, can you try encoding the HTML string 
   (Base64)
   and decoding back (using Javascript Base64 code ) before display on 
   the
   browser?

   On Fri, Apr 24, 2009 at 11:30 AM, Matt guitarroman...@gmail.com 
   wrote:

Hi there,

I'm using PHP to output some JSON through AJAX to my page. It breaks
whenever I use a backslash or quote mark.

I've tried using php's json_encode function which doesn't seem to
help, just breaks it further. I've also tried php's addslashes() to
the output, again, same problem.

Am I approaching this correctly, fundamentally? Is JSON supposed to
contain HTML?

Thanks,

Matt



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-04-24 Thread T.J. Crowder

@Ananth:

Converting to Base64 would be massive overkill, surely.

@OP:

There's no reason you can't include strings containing HTML in JSON
data.  You just have to make sure your strings are valid string
literals, like this:

{
message: pThis is HTML./p
}

There's nothing special other than making sure the HTML is correctly
escaped -- e.g., if you're putting the JSON string in double quotes,
naturally any double quotes in the HTML will need a backslash in front
of them -- as, for that matter, will any backslashes!

HTH,
--
T.J. Crowder
tj / crowder software / com

On Apr 24, 5:05 pm, Ananth Raghuraman araghuram...@gmail.com wrote:
 JSON should not contain HTML for tactical/ease of programming purposes
 unless the HTML is there as part of a larger design, but there may or may
 not be implementation restrictions.
 If you are facing problems, can you try encoding the HTML string (Base64)
 and decoding back (using Javascript Base64 code ) before display on the
 browser?

 On Fri, Apr 24, 2009 at 11:30 AM, Matt guitarroman...@gmail.com wrote:

  Hi there,

  I'm using PHP to output some JSON through AJAX to my page. It breaks
  whenever I use a backslash or quote mark.

  I've tried using php's json_encode function which doesn't seem to
  help, just breaks it further. I've also tried php's addslashes() to
  the output, again, same problem.

  Am I approaching this correctly, fundamentally? Is JSON supposed to
  contain HTML?

  Thanks,

  Matt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-04-24 Thread Ananth Raghuraman
JSON should not contain HTML for tactical/ease of programming purposes
unless the HTML is there as part of a larger design, but there may or may
not be implementation restrictions.
If you are facing problems, can you try encoding the HTML string (Base64)
and decoding back (using Javascript Base64 code ) before display on the
browser?

On Fri, Apr 24, 2009 at 11:30 AM, Matt guitarroman...@gmail.com wrote:


 Hi there,

 I'm using PHP to output some JSON through AJAX to my page. It breaks
 whenever I use a backslash or quote mark.

 I've tried using php's json_encode function which doesn't seem to
 help, just breaks it further. I've also tried php's addslashes() to
 the output, again, same problem.

 Am I approaching this correctly, fundamentally? Is JSON supposed to
 contain HTML?

 Thanks,

 Matt
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: HTML breaks JSON

2009-04-24 Thread Matt Foster

What are you sending to PHP's json_encode?  It is expecting a
structure to serialize into a JSON syntax string.

$struct = array(message = h1Hello World/h1Who says we can't
have any kind of \quotes\ we want?);

echo json_encode($struct);

If you try to run json_encode on your already JSONified string, yeah
its going to cause problems...


--

http://positionabsolute.net



On Apr 24, 12:26 pm, T.J. Crowder t...@crowdersoftware.com wrote:
 @Ananth:

 Converting to Base64 would be massive overkill, surely.

 @OP:

 There's no reason you can't include strings containing HTML in JSON
 data.  You just have to make sure your strings are valid string
 literals, like this:

 {
     message: pThis is HTML./p

 }

 There's nothing special other than making sure the HTML is correctly
 escaped -- e.g., if you're putting the JSON string in double quotes,
 naturally any double quotes in the HTML will need a backslash in front
 of them -- as, for that matter, will any backslashes!

 HTH,
 --
 T.J. Crowder
 tj / crowder software / com

 On Apr 24, 5:05 pm, Ananth Raghuraman araghuram...@gmail.com wrote:

  JSON should not contain HTML for tactical/ease of programming purposes
  unless the HTML is there as part of a larger design, but there may or may
  not be implementation restrictions.
  If you are facing problems, can you try encoding the HTML string (Base64)
  and decoding back (using Javascript Base64 code ) before display on the
  browser?

  On Fri, Apr 24, 2009 at 11:30 AM, Matt guitarroman...@gmail.com wrote:

   Hi there,

   I'm using PHP to output some JSON through AJAX to my page. It breaks
   whenever I use a backslash or quote mark.

   I've tried using php's json_encode function which doesn't seem to
   help, just breaks it further. I've also tried php's addslashes() to
   the output, again, same problem.

   Am I approaching this correctly, fundamentally? Is JSON supposed to
   contain HTML?

   Thanks,

   Matt
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---