Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
75
rated 0 times [  81] [ 6]  / answers: 1 / hits: 28641  / 14 Years ago, wed, october 6, 2010, 12:00:00

I get this response from an Ajax request.
Javascript seems to intepret it as a string.
(When I say alert this.responseText, the whole string is shown)



How can i convert it to a javascript object (JSON)?



{response: {
success: The activity has been removed,
message: 0

}
}


I am not using jquery.


More From » json

 Answers
16

It's not the safest thing in the world, but you can do this:



var value = null, txt = this.responseText;
eval(value = ( + txt + ));


It might be a little safer to do:



var value = null, txt = this.responseText;
!function(window) { eval(value = ( + txt + )); }();


but there are still all sorts of potential hacks. You're better off using a library.


[#95400] Sunday, October 3, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alejandro

Total Points: 231
Total Questions: 102
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
alejandro questions
Mon, Jul 18, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Thu, Sep 10, 20, 00:00, 4 Years ago
;