I have an application that creates a snippet of php in a server, for packaging up data for JSON, using the php package "Pear." The snippet I create (with varying data, of course, as the application runs) is written in php, but I really want to keep things rails-centric. Is there a way to convert this to NOT use php, so that I am entirely Ruby on Rails? Thanks, Janna B <?php ini_set(''include_path'',ini_get(''include_path'').";C:\Program Files \Apache Group\Apache2\htdocs"."\pear"); require(''JSON.php''); $records=array(); $records[]=array(''order''=>1, ''username''=>''joeyt''); $json=new Services_JSON(); echo($json->encode($records)); ?>
On Sat, Jul 4, 2009 at 7:12 PM, JannaB <mistressjanna-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > I have an application that creates a snippet of php in a server, for > packaging up data for JSON, using the php package "Pear." The snippet > I create (with varying data, of course, as the application runs) is > written in php, but I really want to keep things rails-centric. Is > there a way to convert this to NOT use php, so that I am entirely Ruby > on Rails? Thanks, Janna B > > <?php > ini_set(''include_path'',ini_get(''include_path'').";C:\Program Files > \Apache Group\Apache2\htdocs"."\pear"); > require(''JSON.php''); > > $records=array(); > $records[]=array(''order''=>1, ''username''=>''joeyt''); > $json=new Services_JSON(); > echo($json->encode($records)); > ?> >Janna, the above PHP code simply converts a PHP array to JSON format. Thus, you can do the equivalent in Ruby as follows: require "json" records = { order''=>1, ''username''=>''joeyt'' }.to_json Good luck, -Conrad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sat, Jul 4, 2009 at 10:26 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Jul 4, 2009 at 7:12 PM, JannaB <mistressjanna-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > >> >> I have an application that creates a snippet of php in a server, for >> packaging up data for JSON, using the php package "Pear." The snippet >> I create (with varying data, of course, as the application runs) is >> written in php, but I really want to keep things rails-centric. Is >> there a way to convert this to NOT use php, so that I am entirely Ruby >> on Rails? Thanks, Janna B >> >> <?php >> ini_set(''include_path'',ini_get(''include_path'').";C:\Program Files >> \Apache Group\Apache2\htdocs"."\pear"); >> require(''JSON.php''); >> >> $records=array(); >> $records[]=array(''order''=>1, ''username''=>''joeyt''); >> $json=new Services_JSON(); >> echo($json->encode($records)); >> ?> >> > > Janna, the above PHP code simply converts a PHP array to JSON format. > Thus, you can do the equivalent in Ruby as follows: > > require "json" > > records = { order''=>1, ''username''=>''joeyt'' }.to_json >Correction: require "json" records = { ''order''=>1, ''username''=>''joeyt'' }.to_json # Missed the leading quote> Good luck, > > -Conrad > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Magnificent! Thank you Conrad! On Jul 5, 1:30 am, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Jul 4, 2009 at 10:26 PM, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Sat, Jul 4, 2009 at 7:12 PM, JannaB <mistressja...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote: > > >> I have an application that creates a snippet of php in a server, fo > >> packaging up data for JSON, using the php package "Pear." The snippet > >> I create (with varying data, of course, as the application runs) is > >> written in php, but I really want to keep things rails-centric. Is > >> there a way to convert this to NOT use php, so that I am entirely Ruby > >> on Rails? Thanks, Janna B > > >> <?php > >> ini_set(''include_path'',ini_get(''include_path'').";C:\Program Files > >> \Apache Group\Apache2\htdocs"."\pear"); > >> require(''JSON.php''); > > >> $records=array(); > >> $records[]=array(''order''=>1, ''username''=>''joeyt''); > >> $json=new Services_JSON(); > >> echo($json->encode($records)); > >> ?> > > > Janna, the above PHP code simply converts a PHP array to JSON format. > > Thus, you can do the equivalent in Ruby as follows: > > > require "json" > > > records = { order''=>1, ''username''=>''joeyt'' }.to_json > > Correction: > > require "json" > > records = { ''order''=>1, ''username''=>''joeyt'' }.to_json # Missed the leading > quote > > > Good luck, > > > -Conrad