Jump to content

Recommended Posts

I have a PHP array that I passed to javascript via json_encode. Is there any way I could convert it to a javascript array. I have tried using eval to no avail.

 

alert(eval(this.responseText));
eval('newData='+this.responseText);

When i do that, I get the following:

 

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

 

when i dont use eval, i get the following



[{"OB_ID_FEED":"1037","ORG_ID":"flrmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"29045","PREV_COUNTS":"30708","PCT_CHG":"-5.73"},{"OB_ID_FEED":"1023","ORG_ID":"caygaor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"413","PREV_COUNTS":"420","PCT_CHG":"-1.69"},{"OB_ID_FEED":"1042","ORG_ID":"copikes","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"6098","PREV_COUNTS":"6192","PCT_CHG":"-1.54"},{"OB_ID_FEED":"1100","ORG_ID":"tnknox","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"9811","PREV_COUNTS":"9927","PCT_CHG":"-1.18"},{"OB_ID_FEED":"1022","ORG_ID":"cakcbor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"231","PREV_COUNTS":"233","PCT_CHG":"-.87"},{"OB_ID_FEED":"1019","ORG_ID":"cafaor-r","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"4008","PREV_COUNTS":"4032","PCT_CHG":"-.6"},{"OB_ID_FEED":"1147","ORG_ID":"caccrmls-r","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"2539","PREV_COUNTS":"2554","PCT_CHG":"-.59"},{"OB_ID_FEED":"1008","ORG_ID":"catcr","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"679","PREV_COUNTS":"683","PCT_CHG":"-.59"},{"OB_ID_FEED":"1030","ORG_ID":"inmibor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"19313","PREV_COUNTS":"19409","PCT_CHG":"-.5"},{"OB_ID_FEED":"1004","ORG_ID":"camar","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"209","PREV_COUNTS":"210","PCT_CHG":"-.48"},{"OB_ID_FEED":"2000","ORG_ID":"carets","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"55787","PREV_COUNTS":"56032","PCT_CHG":"-.44"},{"OB_ID_FEED":"1024","ORG_ID":"calcaor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"488","PREV_COUNTS":"490","PCT_CHG":"-.41"},{"OB_ID_FEED":"1039","ORG_ID":"comlmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"20301","PREV_COUNTS":"20383","PCT_CHG":"-.4"},{"OB_ID_FEED":"1041","ORG_ID":"txdallas","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"43687","PREV_COUNTS":"43853","PCT_CHG":"-.38"},{"OB_ID_FEED":"1066","ORG_ID":"ksheart","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"18697","PREV_COUNTS":"18762","PCT_CHG":"-.35"},{"OB_ID_FEED":"1150","ORG_ID":"cavcmls-r","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"3839","PREV_COUNTS":"3851","PCT_CHG":"-.31"},{"OB_ID_FEED":"1005","ORG_ID":"caebrd","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"5583","PREV_COUNTS":"5598","PCT_CHG":"-.27"},{"OB_ID_FEED":"1001","ORG_ID":"casfar","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"2322","PREV_COUNTS":"2328","PCT_CHG":"-.26"},{"OB_ID_FEED":"1014","ORG_ID":"cacalv","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"762","PREV_COUNTS":"764","PCT_CHG":"-.26"},{"OB_ID_FEED":"1021","ORG_ID":"careil-r","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"8435","PREV_COUNTS":"8457","PCT_CHG":"-.26"},{"OB_ID_FEED":"1052","ORG_ID":"orrmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"28421","PREV_COUNTS":"28495","PCT_CHG":"-.26"},{"OB_ID_FEED":"1143","ORG_ID":"txaustin","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"12359","PREV_COUNTS":"12389","PCT_CHG":"-.24"},{"OB_ID_FEED":"1002","ORG_ID":"flsemls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"15434","PREV_COUNTS":"15468","PCT_CHG":"-.22"},{"OB_ID_FEED":"1013","ORG_ID":"camlmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"17649","PREV_COUNTS":"17684","PCT_CHG":"-.2"},{"OB_ID_FEED":"1208","ORG_ID":"caacaor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"538","PREV_COUNTS":"539","PCT_CHG":"-.19"},{"OB_ID_FEED":"1071","ORG_ID":"camrmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"17853","PREV_COUNTS":"17886","PCT_CHG":"-.18"},{"OB_ID_FEED":"1038","ORG_ID":"azrmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"38279","PREV_COUNTS":"38342","PCT_CHG":"-.16"},{"OB_ID_FEED":"1135","ORG_ID":"txsabor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"12529","PREV_COUNTS":"12547","PCT_CHG":"-.14"},{"OB_ID_FEED":"1118","ORG_ID":"flecar","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"6860","PREV_COUNTS":"6868","PCT_CHG":"-.12"},{"OB_ID_FEED":"1009","ORG_ID":"cabareis","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"7142","PREV_COUNTS":"7149","PCT_CHG":"-.1"},{"OB_ID_FEED":"1054","ORG_ID":"patrend","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"50659","PREV_COUNTS":"50707","PCT_CHG":"-.09"},{"OB_ID_FEED":"1144","ORG_ID":"coires","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"9738","PREV_COUNTS":"9746","PCT_CHG":"-.08"},{"OB_ID_FEED":"1151","ORG_ID":"gafmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"50179","PREV_COUNTS":"50216","PCT_CHG":"-.07"},{"OB_ID_FEED":"1080","ORG_ID":"njgsmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"17619","PREV_COUNTS":"17631","PCT_CHG":"-.07"},{"OB_ID_FEED":"1086","ORG_ID":"camaxmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"4088","PREV_COUNTS":"4091","PCT_CHG":"-.07"},{"OB_ID_FEED":"1046","ORG_ID":"ilmlsni","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"90247","PREV_COUNTS":"90273","PCT_CHG":"-.03"},{"OB_ID_FEED":"1125","ORG_ID":"miswmar","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"17407","PREV_COUNTS":"17407","PCT_CHG":"0"},{"OB_ID_FEED":"1020","ORG_ID":"casar","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"1398","PREV_COUNTS":"1398","PCT_CHG":"0"},{"OB_ID_FEED":"1145","ORG_ID":"hihonbor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"4449","PREV_COUNTS":"4449","PCT_CHG":"0"},{"OB_ID_FEED":"1207","ORG_ID":"castaor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"878","PREV_COUNTS":"878","PCT_CHG":"0"},{"OB_ID_FEED":"1061","ORG_ID":"flmfr","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"75793","PREV_COUNTS":"75793","PCT_CHG":"0"},{"OB_ID_FEED":"1101","ORG_ID":"scccar","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"12301","PREV_COUNTS":"12301","PCT_CHG":"0"},{"OB_ID_FEED":"1087","ORG_ID":"casocal","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"28473","PREV_COUNTS":"28461","PCT_CHG":".04"},{"OB_ID_FEED":"9046","ORG_ID":"ilmlsni-r","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"94194","PREV_COUNTS":"94150","PCT_CHG":".05"},{"OB_ID_FEED":"1069","ORG_ID":"aztaor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"8303","PREV_COUNTS":"8297","PCT_CHG":".07"},{"OB_ID_FEED":"1045","ORG_ID":"ctconnmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"20340","PREV_COUNTS":"20323","PCT_CHG":".08"},{"OB_ID_FEED":"1068","ORG_ID":"tnmtr-r","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"24509","PREV_COUNTS":"24488","PCT_CHG":".09"},{"OB_ID_FEED":"1051","ORG_ID":"mamlspin","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"35698","PREV_COUNTS":"35666","PCT_CHG":".09"},{"OB_ID_FEED":"1032","ORG_ID":"mdmris","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"73218","PREV_COUNTS":"73147","PCT_CHG":".1"},{"OB_ID_FEED":"1153","ORG_ID":"idswrmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"10662","PREV_COUNTS":"10651","PCT_CHG":".1"},{"OB_ID_FEED":"1059","ORG_ID":"nylibor","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"31643","PREV_COUNTS":"31608","PCT_CHG":".11"},{"OB_ID_FEED":"1149","ORG_ID":"nywchester","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"10880","PREV_COUNTS":"10867","PCT_CHG":".12"},{"OB_ID_FEED":"1047","ORG_ID":"gamls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"59372","PREV_COUNTS":"59286","PCT_CHG":".14"},{"OB_ID_FEED":"1146","ORG_ID":"nhnne","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"21090","PREV_COUNTS":"21059","PCT_CHG":".15"},{"OB_ID_FEED":"1057","ORG_ID":"nccmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"22956","PREV_COUNTS":"22922","PCT_CHG":".15"},{"OB_ID_FEED":"1006","ORG_ID":"cachico","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"2269","PREV_COUNTS":"2265","PCT_CHG":".18"},{"OB_ID_FEED":"1279","ORG_ID":"cacdar-r","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"7946","PREV_COUNTS":"7930","PCT_CHG":".2"},{"OB_ID_FEED":"1029","ORG_ID":"mnrmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"67131","PREV_COUNTS":"66979","PCT_CHG":".23"},{"OB_ID_FEED":"1007","ORG_ID":"nvnnrmls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"10002","PREV_COUNTS":"9978","PCT_CHG":".24"},{"OB_ID_FEED":"1098","ORG_ID":"casmls-r","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"12953","PREV_COUNTS":"12921","PCT_CHG":".25"},{"OB_ID_FEED":"1073","ORG_ID":"flnemls","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"13860","PREV_COUNTS":"13817","PCT_CHG":".31"},{"OB_ID_FEED":"1152","ORG_ID":"nyghv","DATE_CHECKED":"15-OCT-09","CURRENT_COUNTS":"6473","PREV_COUNTS":"6447","PCT_CHG":".4"}]

 

but that doesn't seem to be a valid javascript array. is there a special way I have to use the json_encode function to get the results I want?

The result that you're getting looks fine: it is an array of objects, e.g. newData[0] will contain the first object, newData[1] the second, etc..  You can always use Firebug or some other inspector to take a look at the variable and see exactly what is there. Using alert is pretty crude for debugging values.

its a multidimensional array yes, but it should show the actual array, not just say object Object. if I were to alert my good multidimensional array, it shows the arrays contents.

 

If the result was fine, I wouldn't be asking for help.

 

The problem is when I use the array, its treated as completely empty, and doesn't populate a table I have my normal data populate. I have read a lot of different places that to get an object from a json_encoded string, you just need to use eval, but it doesn't seem to be working

Ahh fixed. I was using a deprecated OCI function (OCIFetchInto) when I should have been using oci_fetch_XXX, and also I was returning an associative array, which was ruining everything. Glad I caught this! everything works perfectly now

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.