Activesupport::JSON.decode crashes on this,

Posted by Waheedi on Stack Overflow See other posts from Stack Overflow or by Waheedi
Published on 2010-02-16T15:01:08Z Indexed on 2010/05/29 16:02 UTC
Read the original article Hit count: 441

Filed under:
|
|
|

I wonder why i cant decode this json string, all what i want is to convert this to a proper Ruby hash, anyone have an idea? i think the array of objects is cracking it ?

Parameters:

{"{\"origins\":"=>{"{\"origin\":\"this\"},{\"origin\":\"dont\"},{\"origin\":\"dont me please\"},{\"origin\":\"and me please\"},{\"origin\":\"dont\"},{\"origin\":\"dont\"},{\"origin\":\"dont\"},{\"origin\":\"okay\"},{\"origin\":\"dont\"},{\"origin\":\"go\"},{\"origin\":\"go\"}"=>{",\"url\":\"file:///Users/waheed/Desktop/untitled.html\",\"apik\":\"helloapik\",\"host\":\"http://localhost:3000/\"}"=>nil}}}

now in my javascript im doing this

//this is the object im trying to send over xmlhttprequest and im using JSON.org library which has the stringify method

 function tObject(origins,url,apik){
    this.origins=origins; //this is an array of string
    this.url=url;
    this.apik=apik; 
}

    var t = new tObject(myStringArr,"www.foo.com","welcome guys");

ajax = new Ajax(); //this is an xhcon class you dont worry about it url here http://xkr.us/code/javascript/XHConn/
ajax.connect("http://localhost:3000/","POST",JSON.stringify(t), callback); 

in my rails app the parameters that has been posted looks like this:

Parameters: {"{\"origins\":"=>{"{\"origin\":\"this\"},{\"origin\":\"yo yo\"},{\"origin\":\" me please\"},{\"origin\":\"and me please\"},{\"origin\":\"here\"},{\"origin\":\"and again\"},{\"origin\":\"again\"},{\"origin\":\"okay\"},{\"origin\":\"yes\"},{\"origin\":\"go\"},{\"origin\":\"go\"}"=>{",\"url\":\"www.foo.com\",\"apik\":\"welcome guys\"}"=>nil}}}

why it results with nil at the last ? i've tried to decode it but it could not work because it blame the string is not json string ?!!?

TIA, waheedi

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ruby-on-rails