简体   繁体   中英

How to display key-value pairs from a JSON object using Angular

I want to print JSON file in HTML page but I don't know the keys and the values my JSON Object.

When I know the form of JSON I use this code:

<div ng-repeat="f in faq">
  <div class="list-group-item clearfix">
    <h4>
      <span class="glyphicon glyphicon-file">
        </span>
          {{f.key}}-{{f.value}}
            <span class="pull-right">
              <button class="btn btn-warning" ng-click="">
                <span class="glyphicon glyphicon-trash">
          </span>
    </button>
    </span>
  </h4>
  </div>
 </div>  
</div>

But in this moment I don't know the keys and the values of the JSON .

Thanks for your help.

Looks like you are using angular(I noticed from ng-repeat). You can use (key,data) as follows:-

<div ng-repeat="(key, data) in faq">
  {{key}} - {{data}}
</div>

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