KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
i have a question to deserialize JSON text to an javascript object, i test jquery and yui library, i have this class: function Identifier(name, contextId) { this.name = name; this.contextId = contextId; } Identifier.prototype.setName = function(name) { this.name = name; } Identifier.prototype.getName = function() { return this.name; } Identifier.prototype.setContextId = function(contexId) { this.contextId= contexId; } Identifier.prototype.getContextId = function() { return this.contextId; } and i have this JSON: { "Identifier": { "name":"uno", "contextId":"dos"} } I want to the parse create an Identifier object, my problem is that this sentences: var obj = jQuery.parseJSON('{"Identifier": { "name":"uno","contextId":"dos"}}'); or var obj2 = JSON.parse('{"Identifier": { "name":"uno","contextId":"dos"}}'); Dont work, the var obj and obj2 aren't an Identifier object, how can i parse this? Thanks This question is not the duplicate, because it was made 5 years before than the question that Michael marks as duplicated
Tags (comma-separated)
Save Edits
Cancel