Я не могу разобрать многострочный массив JSON и поместить его в элементы HTML - PullRequest
0 голосов
/ 26 мая 2019

var dataJSON = '[{"FeeType":"Domestic POS Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"Domestic PIN Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"International POS Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"International PIN Declined Fee ","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"ATM Domestic Fee <sup>1</sup>","FeeDescription":"One (1) no cost ATM withdrawal per deposit1, then $1.75 per transaction thereafter","FeeAmount":"1.75"},{"FeeType":"Domestic ATM Balance Inquiry Fee <sup>1</sup>","FeeDescription":"per ATM Balance Inquiry","FeeAmount":"0.50"},{"FeeType":"Domestic ATM Declined Fee <sup>1</sup>","FeeDescription":"per declined transaction","FeeAmount":"0.50"},{"FeeType":"International ATM Withdrawal Fee <sup>1</sup>","FeeDescription":"per transaction","FeeAmount":"3.00"},{"FeeType":"International ATM Balance Fee ","FeeDescription":"per ATM Balance Inquiry","FeeAmount":"0.95"},{"FeeType":"International ATM Declined Fee","FeeDescription":"per declined transaction","FeeAmount":"0.95"},{"FeeType":"OTC Withdrawal Fee","FeeDescription":"per transaction","FeeAmount":"4.00"},{"FeeType":"International OTC Withdrawal Fee","FeeDescription":"per transaction","FeeAmount":"4.00"},{"FeeType":"Currency Conversion Fee","FeeDescription":"3% of transaction amount","FeeAmount":"3.00%"},{"FeeType":"Card Replacement Fee","FeeDescription":"One (1) no cost replacement per calendar year or upon expiration; $5.00 per request thereafter for lost, stolen, and damaged cards.","FeeAmount":"5.00"},{"FeeType":" Expedited Card Replacement Fee ","FeeDescription":"$20.00 (per Card; an additional fee when a Card is reissued or replaced for any reason with requested expedited delivery)","FeeAmount":"20.00"},{"FeeType":"Check Refund Fee","FeeDescription":"$12.50 per refund check (When a refund check is issued for the remaining Card balance.","FeeAmount":"12.5"}]';


var dataObject = JSON.parse(dataJSON);
var listItemString = $('#listItem').html();

dataObject.forEach(buildNewList);

function buildNewList(item, index) {
  var listItem = $('<li class="collection-item">' + listItemString + '</li>');
  var listItemTitle = $('.title', listItem);
  listItemTitle.html(item.FeeType);
  var listItemDesc = $('.description', listItem);
  listItemDesc.html(item.FeeDescription);
  $('#myUL').append(listItem);
}
            
      
            

var myObj2 = {
 "kelimeler": [
 {
   "title": "",
   "description": "T�rkiyenin en b�y�k do_rudan sat�_ _irketi"
 },
 {
   "title": "Aktif Temsilci",
   "description": "Bir kampanyada sipari_ veren ve �d�l sat�_ tutar� s�f�rdan b�y�k olan temsilci"
 },

] }

Я нашел код в интернете. var dataObject = JSON.parse (dataJSON); это прекрасно работает, но мне очень сложно управлять однострочным массивом json. Я просто хочу использовать myObj2 и получить доступ к заголовку и описанию.

Как я могу получить доступ к элементам внутри myObj2> 'keliemeler'. Я попробовал что-то item.kelimeler.title, но это не сработало.

Спасибо.

1 Ответ

0 голосов
/ 26 мая 2019

item.kelimeler никогда не будет отображаться, так как он находится только в myObj2, а элемент взят из dataJSON без kelimeler.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...