簡體   English   中英

使用AngularJS訪問嵌套JSON

[英]Accessing Nested JSON with AngularJS

我正在嘗試從Behance.net提取數據,當我嘗試獲取信息時遇到了兩個問題。

第一個問題是嘗試提取項目描述。 我可以通過調用ng-bind="project.description"來獲取信息,但是格式(段落返回)不存在,因此我嘗試提取格式的描述。

這是html:

<div class="col-sm-6">
    <h3 ng-bind="project.name"></h3>
    <p ng-bind="project.modules.text"></p>

    <h4><i class="fa fa-tags success"></i> Tags</h4>
    <div class="row">
      <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div class="pull-left label label-info" style="margin-right:5px; margin-bottom:10px;"
              ng-repeat="tag in project.tags" ng-bind="tag"></div>
      </div>
    </div>

這是Behance顯示的JSON數據:

angular.callbacks._0({
    "project": {
    ....
         "modules": [{
            "id": 111549713,
            "type": "text",
            "text": "This is the description of the project I am trying to get"

我猜我的第二個問題與第一個相同,但是在這里。

<p style="margin-top:10px;" ng-bind="user.sections.About"></p>

和JSON文件:

angular.callbacks._1({
    "user": {
       "sections": {
            "About Me": Description used on the behance website that I am trying to display

除了這兩個實例,我可以提取任何信息。 任何幫助將不勝感激。

首要問題:

project.modules是一個數組,因此請嘗試以下方法:

<p ng-bind="project.modules[0].text"></p>

第二期:

由於“關於我”屬性包含一個空格,因此您需要使用方括號符號來訪問它:

<p style="margin-top:10px;" ng-bind="user.sections['About Me']"></p>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM