I am trying to use eval() function to deserialize this JSON text by using eval function.
var personJSON = {
"FirstName": "Burak",
"LastName": "Ozdogan",
"Id": "001",
"Department": "Information Technologies"
};
var personBurakOzdogan = eval('(' + personJSON + ')');
But I am getting this error:
*Microsoft JScript pilation error: Expected ']'*
Is there something that I skip which I cannot catch?
Thanks
I am trying to use eval() function to deserialize this JSON text by using eval function.
var personJSON = {
"FirstName": "Burak",
"LastName": "Ozdogan",
"Id": "001",
"Department": "Information Technologies"
};
var personBurakOzdogan = eval('(' + personJSON + ')');
But I am getting this error:
*Microsoft JScript pilation error: Expected ']'*
Is there something that I skip which I cannot catch?
Thanks
Share Improve this question edited Jan 7, 2020 at 13:24 Mickael Lherminez 6951 gold badge11 silver badges30 bronze badges asked Jun 20, 2010 at 12:31 pencilCakepencilCake 53.4k87 gold badges236 silver badges377 bronze badges4 Answers
Reset to default 6What you have is not JSON text. It is already a JSON object. So you don't need to use eval
at all. You can directly access and manipulate its properties:
alert(personJSON.FirstName);
Try to check if your personJSON is a wrapper that CONTAINS the real json. For example, try to write:
var person = eval('(' + personJSON.Person + ')')
where Person
is the class serialized by the service.
OR
try this:
var person = eval('(' + personJSON.GetPersonResult + ')')
where GetPerson
is the method name in the service, plus Result
.
you are not dealing with a string, but with a json object. You are trying to evaluate a json object as string to create a json object.
var personJSON =
'{"FirstName":"Burak","LastName":"Ozdogan","Id":"001","Department":"Information Technologies"}';
var personBurakOzdogan = eval('(' + personJSON + ')');
this should work, although it doesn't make to much sense. this makes more sense:
var personBurakOzdogan = {
"FirstName": "Burak",
"LastName": "Ozdogan",
"Id": "001",
"Department": "Information Technologies"
};
You have to pass to the variable a string type as the code seen below:
var personJSON = '{"FirstName":"Burak","LastName":"Ozdogan","Id":"001","Department":"Information Technologies"}';