Skip to Content
0
Former Member
Jun 25, 2015 at 04:32 AM

How to read JSON data which is coming from server and store in local variable in SAP UI5?

559 Views

Hello Experts,

I am not able to read the JSON data which is coming from server and I would like to store one value into local variable? It is working fine if I bind the same model to UI controller ,the data is displaying correctly.But I need store one value into local variable.

Here is my code:

var oModelData = new sap.ui.model.json.JSONModel();

var root = window.location.protocol + '//' + window.location.host;

var url = root + "/idmrest/v72alpha/entries/0";

oModelData.loadData(url);

this.getView().setModel(oModelData, "model1");

var zkey = this.getView().getModel("model1").getProperty("/ENTRIES/MSKEYVALUE/VALUE");

and It is saying "undefined" and if I use:

var zkey = oModelData.getProperty("/ENTRIES/MSKEYVALUE/VALUE");

here also it is undefined

can any body please suggest me here? and also how do we get the array and loop it which is inside the JSON (model1)?

Regards,

Kiran