javascript - 来自index.html 文件中的javascript 的JSON

标签 javascript jquery html json angularjs

我有一个简历结构,我正在尝试使用 Json 构建它。简历部分如下:

Cisco
- Software Engineer
    - Try different technologies to make user friendly applications
    - Playing with javascript and Json to create a personal website 

我的 JSON 结构如下:

{
"sections":
[
{
  "company": "Cisco",
  "title":"Software Engineer",
  "desc": 
        [
        {
          "line1": "Try different technologies to make user friendly applications",
          "line2": "Playing with javascript and Json to create a personal website"
        }
        ]
}
] 
}

我在index.html中使用以下脚本来获取json数据:

  <div ng:switch-when="job" itemscope itemprop="organization" itemtype="http://schema.org/Organization">
            <section class="job {{isLast(section.data.length,$index)}}"  ng:repeat="job in section.data">
             <h2>{{job.company|microdata:"name"}}{{job.url|external}}</h2>
             <h3>{{job.title}}</h3>
             <h2>{{job.desc.line1}}</h2>
             <h2>{{job.desc.line2}}</h2>
             </section>
</div>

我没有得到预期的输出 line1 和 line2。我是否做错了什么,或者它渗透到键值对的第 1 级?

我是 json 和 javascript 的新手,所以请指导。谢谢。

最佳答案

Desc 是一个数组,其中包含一个对象。您可能想要更改 JSON,从 data 中删除 [] 括号,然后将其设为对象(即 {})。

{
    "sections": [{
        "company": "Cisco",
        "title": "Software Engineer",
        "desc": {
            "line1": "Try different technologies to make user friendly applications",
            "line2": "Playing with javascript and Json to create a personal website"
        }
    }]
}

关于javascript - 来自index.html 文件中的javascript 的JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22083410/

相关文章:

jquery - 直接链接到表格选项卡

css - 禁用轨道点击输入类型范围

javascript - 将前一个小时和后一个小时添加到数组中

javascript - 使用表单元素中的数据集获取 FormData 的内容

javascript - 是否可以跨窗口域编写脚本?

javascript - 如何增加 Vue 应用程序的 max-http-header-size

javascript - 在 Angular 中动态创建元素

许多异步 HTTP 调用的 JavaScript 事件处理性能

JQuery 自动完成 : how to force selection from list (keyboard)

javascript - 如何增加加载消息的宽度和高度?