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 + ')');

 

Link to comment
Share on other sites

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.