How to run Java code snippets in MATLAB script
显示 更早的评论
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
回答(1 个)
Nirmallya Kundu
2020-11-11
0 个投票
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'});
类别
在 帮助中心 和 File Exchange 中查找有关 JSON Format 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!