cancel
Showing results for 
Search instead for 
Did you mean: 

JSON object returns no data

0 Kudos

Hi All,

After creating a JSON model and loading data on it, i still cannot get the value inside that json object. My code is

var dataPath = "/test/medium.json";

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

oModel.loadData(dataPath);

When i try to print the contents inside the json object, it returns as undefined. The code i use to get object contents is:

alert(oModel.getData());

Can someone please comment on what i missing in my code. Thanks in advance!

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

it is async by default, that's why you cannot get the data immediately.

try oModel.loadData(dataPath,"",false);

0 Kudos

Thanks Jun Wu, your solution did the trick

Answers (1)

Answers (1)

SergioG_TX
Active Contributor
0 Kudos

Abinsh,

your code looks alright. Make sure you have a json response on the relative url you specified for your JSON model. If the url is correct, then there may be an issue on how you create the JSON model itself.

try:

var path = "<YOUR_PATH>";

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

// see if you have data at this point ... this may be the issue due to the correct way to specify the url

here is the documentation

also you should look at how the setData property of the model is being used on the controls tab

good luck

0 Kudos

Hi Sergio, Thanks for the response. I tried what you suggested but still had the issue