Skip to Content
0

UI5 Not able to load a JSON file.

Mar 24, 2017 at 12:58 PM

136

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

avatar image
Former Member Mar 24, 2017 at 01:51 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Mar 24, 2017 at 03:23 PM
0

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

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 24, 2017 at 03:17 PM
0

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
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 24, 2017 at 03:39 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded