Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How do I convert a JavaScript object to a TJSONObject?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0
Brian Wheatley

Posts: 60
Registered: 2/5/01
How do I convert a JavaScript object to a TJSONObject?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 2:07 PM
Hello,

I am working on a server that uses XML-RPC for remote procedure calls as shown below:

this.validateLogin = function(user, company, password) {
console.log(JSON.toString(user) + ", " + JSON.toString(company) + ", " + password);
xmlrpc.callMethod('login', [{
User: user,
Company: company,
Password: password
}]).then(function(response){
console.log(response);
if (response === 'OK') {
return true;
} else if (response === 'Fail') {
return false;
};
}, function(err){
console.log("Error validating login: " + JSON.stringify(err));
});
};

Password is a string. User and Company are JavaScript objects.

What I receive on the server is show below.

'(Oid={8D03643A-CAEA-4A21-8563-3E0890E30634}; UserName=Zachary Cobb; CertificationNumber=OSHA-CERT007; Companies=(Oid={D014A27E-0003-4A5D-8BD7-E37A772DEEDC}; Name=Remarkable Scales & Service; $$hashKey=object:18); $$hashKey=object:6)'

The TJSONObject.ParseJSONValue() method returns nil when I pass this string to it.

The only way that I can get this all to work properly is to stringify the objects.

this.validateLogin = function(user, company, password) {
console.log(JSON.toString(user) + ", " + JSON.toString(company) + ", " + password);
xmlrpc.callMethod('login', [{
User: JSON.stringify(user),
Company: JSON.stringify(company),
Password: password
}]).then(function(response){
console.log(response);
if (response === 'OK') {
return true;
} else if (response === 'Fail') {
return false;
};
}, function(err){
console.log("Error validating login: " + JSON.stringify(err));
});
};

Is there a way to handle this without calling stringify for every object?

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02