Topic: JSON eval() problems with IE |
|
|---|---|
| Author | Thread |
|
Bipolar (III) Inmate From: LA, CA, USA |
posted 06-07-2007 01:24
I'm trying to load a Yahoo widget DataTable by using some JSON data that I have created myself dynamically. I can get the DataTable to load and the example works in Firefox, but it won't work in IE. code: <script type="text/javascript">
var sample_input_data = "0.0,1.0:1.0,21.0:2.0,321.0:3.0,2005.0:4.0,7737.0:5.0,22461.0:6.0,54121.0:7.0,114381.0:8.0,219345.0:9.0,390277.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:";
var myColumnHeaders = [ {key:"areacode",className:"col1"}, {key:"state",className:"col2"}];
var myColumnSet = new YAHOO.widget.ColumnSet(myColumnHeaders);
var myDataSource2 = new YAHOO.util.DataSource(formatStringToJSON(sample_input_data));
myDataSource2.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
myDataSource2.responseSchema = { fields: ["areacode","state"] };
var myDataTable = new YAHOO.widget.DataTable("scroll",myColumnSet,myDataSource2,{scrollable:true});
function formatStringToJSON(inputString)
{
var point_sets = inputString.split(":");
var json_text = "";
for (x = 0; x < point_sets.length-1; x++)
{
var point = point_sets[x].split(",");
json_text += "{ x: " + point[0] + ", y: " + point[1] + "}, ";
}
json_text = '( [' + json_text + '] )';
//var data_points = eval ( ' { points: [' + json_text + '] }');
var data_points = eval( '{ areacodes: [ { areacode: \"201\", state: \"New Jersey\"}, ] }' );
return data_points;
}
</script>
|
|
Paranoid (IV) Inmate From: Norway |
posted 06-07-2007 03:10
|
|
Bipolar (III) Inmate From: LA, CA, USA |
posted 06-08-2007 00:59
Ok, so I played with it some more taking into account your advice. I got some interesting results. code: var sample_input_data = "0.0,1.0:1.0,21.0:2.0,321.0:3.0,2005.0:4.0,7737.0:5.0,22461.0:6.0,54121.0:7.0,114381.0:8.0,219345.0:9.0,390277.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:10.0,654321.0:";
var myColumnHeaders2 = [
{key:"x",className:"col1"},
{key:"y",className:"col2"}
];
var myColumnSet2 = new YAHOO.widget.ColumnSet(myColumnHeaders2);
var jsonPoints = formatStringToJSON(sample_input_data);
alert(jsonPoints.data_points)
var myDataSource2 = new YAHOO.util.DataSource(jsonPoints.data_points);
myDataSource2.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
myDataSource2.responseSchema = { fields: ["x","y"] };
var myDataTable2 = new YAHOO.widget.DataTable("scroll",myColumnSet2,myDataSource2,{scrollable:true});
function formatStringToJSON(inputString)
{
var point_sets = inputString.split(":");
var json_text = "";
for (x = 0; x < point_sets.length-1; x++)
{
var point = point_sets[x].split(",");
json_text += "{ x: \"" + point[0] + "\", y: \"" + point[1] + "\"}, ";
}
return eval( 'data_points = { points: [' + json_text + '] } '); // return 1.
//return eval( ' { points: [' + json_text + '] } '); // return 2.
}
|
|
Paranoid (IV) Inmate From: Norway |
posted 06-08-2007 11:26
|