Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9369

Reading JSON data SAPUI5

$
0
0

Hi Experts

 

I am trying to create a page that will build elements containing the results of a JSON query. I have a public source that returns JSON data.

 

http://services.odata.org/Northwind/Northwind.svc/Employees?$format=json

 

I want to use a couple of fields to populate a SPAUI5 webpage

 

The code below is just one of my failed attempts.(As you will see I really have little idea how to go about it.) Can someone guide me on how I can access the contents of the call?

 

 

// Code starts here

//===============

var aUrl = 'http://services.odata.org/Northwind/Northwind.svc/Employees';

 

 

var oJSON;

jQuery.ajax({

  url: aUrl,

  method: 'GET',

  async: false,

  dataType: 'json',

  success: function(data) {

      alert('Successful in json call ');

      oJSON = JSON.parse(response.body);

  },

  error: function() {alert('Error in json call ');}

});

 

// Loop through the JSON data

var i = 0;

for(i=0;i<6;i++){                                   // arbitrary limit of 6 rows

  oCell1 = new sap.ui.commons.layout.MatrixLayoutCell({

      colSpan: 2,

      content: new sap.ui.commons.TextView({text:oJSON.value[i].LastName, design: sap.ui.commons.TextViewDesign.Bold }),

  });

  oCell2 = new sap.ui.commons.layout.MatrixLayoutCell({

      colSpan: 3,

      content: new sap.ui.commons.TextView({text:oJSON.value[i].Title})

  });

 

  oMatrix.addRow(

  new sap.ui.commons.layout.MatrixLayoutRow(

      {height: "18px", cells:[oCell1,oCell2]}

     )

  );

}

 

// End of code

// ===========


Viewing all articles
Browse latest Browse all 9369

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>