First I have my data encoded in the json_encode function.
Looks like this for example:
{\"test\":\"test value\"}
What I want to do is m
Objects are associative arrays. They store key/values pairs. So All you have to do is:
var test = function(){}
test["hello"] = "world";
This will set hello
as a variable and world
as its value.
you can test this by doing
alert(test.hello);
Replace hello
and world
with the json key and value
Hope this help more with this example: I am using Jquery AJAX to go to index.php resource and return a json object.
index.php
'world');
echo json_encode($variables);
?>
example.html
var test = function(){}
$.ajax({
url: index.php,
success: function(json) {
for(var key in json ){
var testVarName = key;
var testVarValue = json[key];
test[testVarName ] = testVarValue;
}
}
});
So now test
object has variable hello
and it value is world