Ask away

JSON component acess error

Larry 05/19/17 17:08

35 views

Question CategoryComponent,Server,Data Binding

Number of completed projects0

Question StatusUnsolved

  • JSON
  • Data interface
  • error

Question

I've recently been working on the NEST application using JSON to create a dynamic feel. I have however recently hit a bit of a brick wall... The following function is used to parse some delivery data (irrelevant) into jquery mobile: function parseProdData(results) { var html = ''; for (day in results.deliveries) { var today = results.deliveries[day].delivery; var today_date_arr = today.date.split('-'); var today_date = today_date_arr[2]+'/'+today_date_arr[1]+'/'+today_date_arr[0]; html += '<li><a href="#">'; html += today.delivery_day+', '+today_date; html += '</a></li>'; console.log(html); } $('#JSON-list').append(html); $('#JSON-list').trigger('create'); $('#JSON-list').listview('refresh'); } Now all this looks like its working fine as when I check the console log I get: <li><a href="#">Thursday, 27/02/2014</a></li><li><a href="#">Friday, 28/02/2014</a></li><li><a href="#">Monday, 03/03/2014</a></li><li><a href="#">Tuesday, 04/03/2014</a></li><li><a href="#">Wednesday, 05/03/2014</a></li><li><a href="#">Thursday, 06/03/2014</a></li><li><a href="#">Friday, 07/03/2014</a></li> Thus showing that it is accessing both the date and time attribute correctly. However, straight after this, I get an uncaught type error: Uncaught TypeError: Cannot read property 'date' of undefined From my understanding of JS this should only happen when the relevant attribute is unset. As we can see from the HTML output in the console, this is not the case as it is being accessed correctly. Finally, I get exactly the same error (with delivery_day as the 'undefined' attribute) if I restrict the code to just the delivery day. For those who would like it, below is a sample of the JSON code used: { "deliveries":[ { "delivery":{ "delivery_day":"Thursday", "date":"2017-02-27" } }, { "delivery":{ "delivery_day":"Friday", "date":"2017-02-28" } } ] } Does anyone have any idea why this error is popping up?

Answers

0

Answer

Project

Image

Comment