<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Create a JSON Model from data in file in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973629#M3587993</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi maksim&lt;/P&gt;&lt;P&gt;I do not have any servlets...the war file does contain the json file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well, the problem was the folders were under the webcontent-&amp;gt;projectname, rather than under the webcontent folder &lt;SPAN __jive_emoticon_name="silly" __jive_macro_name="emoticon" class="jive_macro_emoticon jive_macro jive_emote" src="https://community.sap.com/408/images/emoticons/silly.gif"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I fixed the folder structure..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sandip&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Dec 2013 16:19:03 GMT</pubDate>
    <dc:creator>SandipAgarwalla</dc:creator>
    <dc:date>2013-12-10T16:19:03Z</dc:date>
    <item>
      <title>Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaq-p/9973620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;How do we create a JSON Model for the data which is defined in a .json file in the project resources&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g. my data is stored in data.json file which is under models folder.&lt;/P&gt;&lt;P&gt;Now I need to create a model for it, I tried&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;var json = new sap.ui.model.json.JSONModel("/models/data.json");&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;json.setData({modelData:"sampleData"});&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;json.attachRequestCompleted(oData, function(){&lt;/P&gt;
&lt;P&gt;&amp;nbsp; sap.ui.getCore().setModel("json",json);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var nLength = json.getData().d.results.length;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp; alert(nLength);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; });&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it didn't work. The data.json has the format&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;var sampleData = [&lt;/P&gt;
&lt;P&gt;{&amp;lt;somedata&amp;gt;&lt;SPAN style="font-size: 10pt;"&gt;},&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;{&amp;lt;somedata&amp;gt;&lt;SPAN style="font-size: 10pt;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any pointers??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sandip&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 17:52:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaq-p/9973620</guid>
      <dc:creator>SandipAgarwalla</dc:creator>
      <dc:date>2013-12-03T17:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973621#M3587985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandip,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just had a look in the SDK examples. This is one way to load JSON data from a file:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;// Data is fetched here&lt;/P&gt;
&lt;P&gt;&amp;nbsp; jQuery.ajax("Data.json", {&amp;nbsp;&amp;nbsp; // load the data from a relative URL (the Data.json file in the same directory)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; dataType: "json",&lt;/P&gt;
&lt;P&gt;&amp;nbsp; success: function(data){&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var oModel = new sap.ui.model.json.JSONModel(data);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; view.setModel(oModel);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; });&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In that case the JSON file format is like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "countries" : [ {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "name" : "Greece",&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "short" : "GR",&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "detailInfo": {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "capital": "Athens",&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "population": 10787690,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "area": 131990,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "currency": "Euro",&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; "flagUrl": "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Flag_of_Greece.svg/200px-Flag_of_Greece.svg.png"&gt;http://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Flag_of_Greece.svg/200px-Flag_of_Greece.svg.png&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; },...&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hth,&lt;/P&gt;&lt;P&gt;Simon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 22:38:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973621#M3587985</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-12-03T22:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973622#M3587986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandip,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JSON format could be validated with &lt;A href="http://jsonlint.com/" title="http://jsonlint.com/"&gt; JSONLint - The JSON Validator. &lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Calling method &lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #f8f8f8;"&gt;setData&lt;/SPAN&gt; is not required.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below example might help&lt;/P&gt;&lt;P&gt;&lt;A href="http://plnkr.co/edit/JMfSKGrA1xUimj9kzamO?p=preview"&gt;http://plnkr.co/edit/JMfSKGrA1xUimj9kzamO?p=preview&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards, Venkatesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 05:41:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973622#M3587986</guid>
      <dc:creator>former_member91307</dc:creator>
      <dc:date>2013-12-04T05:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973623#M3587987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Simon, Venkat&lt;/P&gt;&lt;P&gt;I tried both the approaches, but still get a problem - 4040 Not found&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px;"&gt;GET &lt;A class="webkit-html-resource-link" href="http://localhost:8080/zui5_trip_confirmation/models/data.json" style="color: #545454;" title="http://localhost:8080/zui5_trip_confirmation/models/data.json"&gt;http://localhost:8080/&amp;lt;projectName&amp;gt;/models/data.json&lt;/A&gt; 404 (Not Found)&lt;/SPAN&gt;&lt;SPAN style="color: #ff0000; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So the problem is somewhere else. I tried loading the resources but no help&lt;/P&gt;&lt;P&gt;sap.ui.localResources("&amp;lt;projectName&amp;gt;/models");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW, the json defined in the file had a minor issue. that is fxed - thanks venkat&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;BR /&gt;Sandip&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 17:08:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973623#M3587987</guid>
      <dc:creator>SandipAgarwalla</dc:creator>
      <dc:date>2013-12-04T17:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973624#M3587988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandip,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please find attched snap shot of project structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards, Venkatesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Dec 2013 17:41:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973624#M3587988</guid>
      <dc:creator>former_member91307</dc:creator>
      <dc:date>2013-12-04T17:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973625#M3587989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Venkat&lt;/P&gt;&lt;P&gt;Still cant get it to work. I have the view defined in a separate folder.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so i tried&lt;/P&gt;&lt;P&gt;var json1 = new sap.ui.model.json.JSONModel("./models/data.json");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;note the period before /model&amp;gt; but error &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px;"&gt;GET &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://localhost:8080/zui5_trip_confirmation/models/data.json" style="font-size: 12px; font-family: Consolas, 'Lucida Console', monospace; color: #3778c7; text-decoration: underline !important;"&gt;http://localhost:8080/&amp;lt;projectName&amp;gt;/models/data.json&lt;/A&gt;&lt;SPAN style="color: #ff0000; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px;"&gt; 404 (Not Found)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px;"&gt;Sandip&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 17:22:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973625#M3587989</guid>
      <dc:creator>SandipAgarwalla</dc:creator>
      <dc:date>2013-12-05T17:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973626#M3587990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandip,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you post a sanp shot of folder structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could try the following too&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;1. sap.ui.localResources("&amp;lt;project_name&amp;gt;");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;2. var json1 = new sap.ui.model.json.JSONModel("models/data.json");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 12px;"&gt;Thanks and Regards, Venkatesh&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 17:57:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973626#M3587990</guid>
      <dc:creator>former_member91307</dc:creator>
      <dc:date>2013-12-05T17:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973627#M3587991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Venkat&lt;/P&gt;&lt;P&gt;I already tried with jQuery.sap.require();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the project structure &lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/jiveimages/337699" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I even noticed the same problem if I add any image from the folder e.g. to a button icon&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sandip&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Dec 2013 04:18:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973627#M3587991</guid>
      <dc:creator>SandipAgarwalla</dc:creator>
      <dc:date>2013-12-06T04:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973628#M3587992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sandip, check the .war file to make sure it contains &lt;SPAN style="color: #333333; font-size: 11.818181991577148px;"&gt;data.json file.&lt;/SPAN&gt; BTW, do you have any servlets in web project?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Dec 2013 04:54:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973628#M3587992</guid>
      <dc:creator>former_member182372</dc:creator>
      <dc:date>2013-12-06T04:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a JSON Model from data in file</title>
      <link>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973629#M3587993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi maksim&lt;/P&gt;&lt;P&gt;I do not have any servlets...the war file does contain the json file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well, the problem was the folders were under the webcontent-&amp;gt;projectname, rather than under the webcontent folder &lt;SPAN __jive_emoticon_name="silly" __jive_macro_name="emoticon" class="jive_macro_emoticon jive_macro jive_emote" src="https://community.sap.com/408/images/emoticons/silly.gif"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I fixed the folder structure..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sandip&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Dec 2013 16:19:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/create-a-json-model-from-data-in-file/qaa-p/9973629#M3587993</guid>
      <dc:creator>SandipAgarwalla</dc:creator>
      <dc:date>2013-12-10T16:19:03Z</dc:date>
    </item>
  </channel>
</rss>

