请原谅我,如果这很简单,但这是我第一次使用JSON。我从C#web方法返回了以下数据(这只是一个缩短的例子):
{
"directors": [
{
"company level": "11",
"name": "ALDI",
"desc": "ALDI now has over 1,200 stores in 32 states, and 4,000 locations worldwide. As the low price grocery leader, our highly successful business model is built on creating efficiencies at every level — from store construction to distribution to the specific products we stock. And one of the many reasons we thrive is our adherence to a simple principle that guides everything we do: if it doesn't maximize sales or reduce expenses, then it's not right for ALDI. It takes a unique person. Someone who is driven. Reliable. And ready to earn the rewards — like higher salaries, generous vacation time, and great benefits — that come from a successful career at ALDI. We're committed to recruiting the best and the brightest in the industry. Because we know that our company's success depends on you.",
"fb": "https://www.facebook.com/ALDI.USA",
"twit": "",
"linked": "http://www.linkedin.com/company/aldi-stores",
"web": "http://www.aldiuscareers.com/",
"tile": "aldi.png",
"logo": "aldi.png"
},
{
"company level": "11",
"name": "Cisco",
"desc": "Cisco Systems is the worldwide leader in networking for the Internet. Today, networks are an essential part of business, education, government and home communications, and Cisco Internet Protocol-based (IP) networking solutions are the foundation of these networks. Our hardware, software, and service offerings are used to create Internet solutions that allow individuals, companies, and countries to increase productivity, improve customer satisfaction and strengthen competitive advantage. The concept of solutions being driven to address specific customer challenges has been with Cisco since its inception. At Cisco we believe community belongs to everyone and connecting and collaborating with others is a key element of our culture.",
"fb": "",
"twit": "",
"linked": "",
"web": "http://www.cisco.com/web/learning/index.html",
"tile": "Cisco.png",
"logo": "CISCO.png"
},
...
], //close directors
"executives": [
//similar markup as above
],
//and one more level
}
我在页面上有一堆静态创建的<divs>
我想要处理这些数据。每个div都包含一个类名,我用它来确定应该用哪个级别填充该tile。
目前,我正在尝试使用变量来跟踪JSON中每个级别的“导演”,“管理人员”或“公司”的位置。然后我使用此变量来获取数据,但我得到cannot read property 0 of undefined
。这是我的代码:
var dPos = 0, ePos = 0, cPos = 0;
var cur;
var info;
$(".partner-tile").each(function() {
cur = $(this);
if (cur.hasClass("big")) {
info = result.directors[dPos]; //where result is the json response
name = info.name;
console.log(name);
}
// and so on
});
我是否尝试错误地访问这些级别?如果是这样,有人能指出我正确的方向吗?
由于