我有一个简历结构,我正在尝试使用 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/