JannaB
(JannaB)
July 5, 2009, 2:12am
1
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));
?>
Con
(Con)
July 5, 2009, 5:26am
2
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
Con
(Con)
July 5, 2009, 5:30am
3
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
JannaB
(JannaB)
July 5, 2009, 11:49am
4
Magnificent! Thank you Conrad!