cancel
Showing results for 
Search instead for 
Did you mean: 

UI5 Not able to load a JSON file.

gary_king2
Participant
0 Kudos

We are using the eclipse IDE and have a standard project set up. However, we are able to load in a json file. The statement that performs the load does not cause an error as such, as processing continues, but we do get a 404 error in the console when debugging.

I json file is stored in the 'model' subdirectory of the project, and the json file is called Testmodel.json. We have tried:

oModel1.loadData("model/Testmodel.json");
oModel1.loadData("Testmodel.json");
var oModel1 = new sap.ui.model.json.JSONModel("Testmodel.json");
var oModel1 = new sap.ui.model.json.JSONModel("model/Testmodel.json");

And we have attempted to load it by setting the model in the manifest, but alas no joy.

I'm pretty sure it's some kind of resource issue. Our resource settings in the index.html are:

<scriptid="sap-ui-bootstrap"
src="resources/sap-ui-cachebuster/sap-ui-core.js"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-compatVersion="edge"
data-sap-ui-resourceroots='{"tabLayout": ""}'
data-sap-ui-bindingSyntax="complex">
</script>

But so far nothing I can do will load a json file.

Accepted Solutions (0)

Answers (4)

Answers (4)

gary_king2
Participant

Thanks to everyone that replied. I have actually tried all those options, of which none worked. However, I have resolved it, and it was incredibly simple, but cause so much grief.

In out index.html file we had an entry saying:

data-sap-ui-resourceroots='{"tabLayout": ""}'

Which we changed it to:

data-sap-ui-resourceroots='{"tabLayout": "."}'

with the full-stop having the effect. We had previously tried this with “./”, but that did not work.

So now our json file can be loaded via all of the methods I mentioned in my post, including declaring a model in the manifest.

Regards to all.

junwu
Active Contributor
0 Kudos

var oRootPath = jQuery.sap.getModulePath("replace.with.your.namesapce"); //could be "tabLayout" in your case

YOURJSONMODEL.loadData(oRootPath + "/model/Testmodel.json", null, false);

Former Member
0 Kudos

Hi Gary,

Normally the structure for your application will be like this projectname/webapp/model/yourjsonfile.json
in model folder you will keep your json file. If structure is like above you can use try like this

var oModel=new sap.ui.model.json.JSONModel("projectname/webapp/model/yourjsonfile.json");if you want to bind this  to any control then get the id of that control and bind like this

//model without name

var selectid= this.getView().byId("controlsidtobind").setModel(oModel);Thanks,Abul Ehtesham
Thanks,
Abul Ehtesham
former_member203031
Contributor
0 Kudos

Hi Gary,

While defining the path please maintain like this "/projectname/model/testmodel.json".

Kindly check and let me know if there is any issue.

Thanks,

Deepak Raj.