简体   繁体   中英

Problems displaying data from nested JSON structure

I'm working on Sharepoint page where i want to retrieve data from the build in REST service. The data resides in a multilayer JSON structure.

The JSON structure: JSON file

I want to fetch data from the first entry ( entry[0] ), located under Feed -> Entry But I can't seem to find the right way to collect and display this.

My code:

<script>
$( document ).ready(function() {
  $.ajax({
         url: "http://intra.site.com/_vti_bin/ListData.svc/ExchangeRates?    $orderby=Modified%20desc",
         headers: { 'accept': 'application/json;odata=verbose', 'content-type': 'application/json;odata=verbose'},
         success: function(data){ 
                document.getElementById("rest_test").innerHTML =
                "<b>" + data.feed.entry[0].title + "</b>";
              }  
       });
  });

The code should display the title object from the first entry ( entry[0] ), but doesn't return, not even undefined .

Any advice on how I can retrieve data from a nested JSON structure?

Thx in advance.

EDIT:

Image of console output: Link

I assume by looking at your comments and the screenshot that your object is somehow mixed up. If ApprovedRate is one of the properties that your entry s have you shoud try running console.log(data.d.results[0]) to get the object that you were trying to get with data.feed.entry[0] . Or am I misunderstanding your structure? A larger screenshot might help in that case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM