我在添加XHR请求以查询JSON到我的脚本时遇到问题, 我很少与之合作,所以它给了我很多问题。我知道 我需要查询一个JS文件,我需要选择 从数组中的匹配,但我完全难以理解如何做到这一点。 我需要做的其他事情是每次发出请求时计算匹配。
类别startList是我现在使用的,它并没有真正填充 在我开始使用之前,我只是想让它先工作 JSON。谁能在这帮助我?
var categories = []; categories["startList"] = ["Men","Women"] categories["Men"] = ["Red","Blue","Multi"]; categories["Red"] = ["Leather","Metal","Ceramic","Plastic"]; categories["Leather"] = ["",""]; categories["Metal"] = ["",""]; categories["Ceramic"] = ["",""]; categories["Plastic"] = ["",""]; categories["Blue"] = ["This","That","Neither"]; categories["Multi"] = ["One","Two","Other"]; categories["Women"] = ["Green","Hot Pink","Multi"]; categories["Green"] = ["Them","Those","Moo"]; categories["Hot Pink"] = ["The","Quick","Brown"]; categories["Multi"] = ["Three","Four","Other"]; var nLists = 6; function fillSelect(currCat,currList){ var step = Number(currList.name.replace(/\D/g,"")); for (i=step; iHere is a quick sample of one of the JSON fields I will want to query.
{ "idName": "The Time Teller", "forGender": "m", "caseDiameter": 1.5, "caseThickness": 0.5, "bandWidth": 0.78, "itemWeight": 1.44,{ "sku": 155320,{ "color1": "white", "color2": "none", "price": 59.99, "cat": "29400", "img": "155320-0002-front", "sku": 155411,{ "color1": "blue", "color2": "none", "price": 59.99, "cat": "32579", "img": "155411-0005-front", "sku": 160041,{ "color1": "black", "color2": "pink", "price": 59.99, "cat": "38404", "img": "160041-0001-front", }, "specialInformation": [ { "restrictions": "Available for US customers only." "detail": "Custom 3 hand Japanese quartz movement.", "detail": "100 meter molded polycarbonate case.", "detail": "Hardened mineral crystal.", "detail": "Locking looper and polycarbonate buckle.", }, { "desc": "Nixon's The Time Teller watch keeps it simpleton with hard case and custom molded polyurethane band."' } ] }
答案 0 :(得分:0)
您的JSON数据错误。例如像
这样的块{ "color1": "white", "color2": "none", "price": 59.99,
"cat": "29400", "img": "155320-0002-front",
应该替换为
{ "color1": "white", "color2": "none", "price": 59.99,
"cat": "29400", "img": "155320-0002-front" },
但并非所有错误。我建议您在http://www.jsonlint.com/中验证您的JSON数据。在http://www.json.org/上,您将获得JSON格式的描述。
以下是可能正确的JSON数据的示例
{
"idName": "The Time Teller",
"forGender": "m",
"caseDiameter": 1.5,
"caseThickness": 0.5,
"bandWidth": 0.78,
"itemWeight": 1.44,
"items": [
{
"color1": "white",
"color2": "none",
"price": 59.99,
"cat": "29400",
"img": "155320-0002-front",
"sku": 155411
},
{
"color1": "blue",
"color2": "none",
"price": 59.99,
"cat": "32579",
"img": "155411-0005-front",
"sku": 160041
},
{
"color1": "black",
"color2": "pink",
"price": 59.99,
"cat": "38404",
"img": "160041-0001-front",
"sku": 155320
}
],
"specialInformation": {
"restrictions": "Available for US customers only.",
"details": [
"Custom 3 hand Japanese quartz movement.",
"100 meter molded polycarbonate case.",
"Hardened mineral crystal.",
"Locking looper and polycarbonate buckle."
],
"desc": "Nixon's The Time Teller watch keeps it simpleton with hard case and custom molded polyurethane band."
}
}