How to run Java code snippets in MATLAB script

2 views (last 30 days)
I need to pull JSON info from a web database. The web API has a java interface. For example, to login, the example Java code is: $.ajax({
url: 'https://mrn.eotpro.net/webapi/jsonp/' + 'Login',
dataType: 'jsonp',
// Data to be sent along with the request
data: { username: 'yourUserName', password: 'yourPassword' },
success: function (json) {
// check the status value
if (json.status === 0) {
// save the access key in a global variable
accessKey = json.key;
}
// Other Activities
. . .
},
error: function () {
// TO DO: when the ajax call failed
}
});
But HOW to execute this from MATLAB? Specifically, within a .m script. Obviously, I know the login and password. But once I've logged in, how to I query the JSON information to get it into a MATLAB variable? I have seen the JSON parsers in the File Exchange and believe I can use one of them along with the MATLAB 'urlread' function.
I've seen several similar questions in the Answers section here but few replies. Should I be asking the question in a different manner? Or is the answer simply not that straight forward? Any helpful information or guidance would be much appreciated!
Kind regards, Dwayne

Answers (1)

Nirmallya Kundu
Nirmallya Kundu on 11 Nov 2020
Hi Dwayne,
You may use the below MATLAB code to achieve the above:
>> URL = 'https://mrn.eotpro.net/webapi/jsonp/Login';
>> status = urlread(URL,'Get',{'username','yourUserName', 'password', 'yourPassword'});

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!