简体   繁体   English

使用AngularJS访问嵌套JSON

[英]Accessing Nested JSON with AngularJS

I'm trying to pull data from Behance.net and I'm running into two issues when I try to get the information. 我正在尝试从Behance.net提取数据,当我尝试获取信息时遇到了两个问题。

The first issue is trying to pull the description of the project. 第一个问题是尝试提取项目描述。 I can get the information by calling ng-bind="project.description" but the formatting (paragraph returns) is not present, so I'm trying to pull the formatted description. 我可以通过调用ng-bind="project.description"来获取信息,但是格式(段落返回)不存在,因此我尝试提取格式的描述。

Here is the html: 这是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>

Here is the JSON data Behance is showing: 这是Behance显示的JSON数据:

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

My second issue I'm guessing is the same as the first, but here it is. 我猜我的第二个问题与第一个相同,但是在这里。

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

and the JSON file: 和JSON文件:

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

I can pull any information except these two instances. 除了这两个实例,我可以提取任何信息。 Any help would be greatly appreciated. 任何帮助将不胜感激。

First issue: 首要问题:

project.modules is an array, so try this instead: project.modules是一个数组,因此请尝试以下方法:

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

Second issue: 第二期:

As the property 'About Me' contains a space you will need to use the bracket notation to access it: 由于“关于我”属性包含一个空格,因此您需要使用方括号符号来访问它:

<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