Jump to content

[SOLVED] A little (which turns out to be a big) problem!!


Mardoxx

Recommended Posts

I am using JSON but I get my Object data as a string. Is there any way to convert the stringed object text to an Object?

 

var Object = {"bindings": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ]
};

 

That code creates an object called myJSONObject, correct? (yes)

 

BUT how can I do this?

Convert the String to an object

 

var String = '{"bindings": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ]
}';

 

var Object = eval(String);

does not work...

 

any ideas?

 

 

 

OH MY GOD I'M SUCH A RETARD

check this:

I had the code x = tmp.load( JSON.stringify(data_1) );

 

so all I needed to do was

x = tmp.load(data_1);

 

PROTIP: GET SOME SLEEP

 

 

 

but as a general case I found this:

var object = eval( '(' + string + ')');

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.