Reputation: 7029
I have a JSON response. The json post is: SubmitPerformedDeed. And i get this back:
{"error":false,"shareurl":"http://groenedaad-dev.lostboys.nl/?isnew=1&pid=155#pid=155","title":"Eigenhandig m’n kantoor een stukje duurzamer gemaakt. Check m’n Groene Daad voor vandaag!","pid":155,"firstname":"sdf","deedpoints":2,"deednumber":20,"deedtitle":"deed 20","company":"asdfsdf","office":"ass","alias":"sdfsxx","thumbnail":"/Uploads/Deeds/155/thumbnail.jpg"}
But how can i put that Json value's response in jquery. How can i put that in a array or ?
Upvotes: 0
Views: 230
Reputation: 2412
you can use
$.each({your returned json},funciton(key,value){
});
here each function can iterate over each json element. so in loop's first iteration key represent "error" and value represent the "false" and so on. now you can store/use this method in accordance with your need.
Upvotes: 0
Reputation: 18979
You can use jQuery.parseJSON(response.responseText) in your success callback
Upvotes: 0
Reputation: 101543
Use .parseJSON()
and .each()
:
var parsedData = $.parseJSON(str);
$.each(parsedData, function(key, value) {
console.log(key + ': ' + value);
});
You should actually be able to just use .each()
for this, as it's a "generic iterator function":
$.each(str, function(key, value) {
console.log(key + ': ' + value);
});
Someone please correct me if I'm wrong.
Upvotes: 2
Reputation: 8098
There is javascript out there that will take a JSON response and put it back in to a javascript object:
var myObj = JSON.parse(result);
Upvotes: 1